diff --git a/tools/cfspack/README.md b/tools/cfspack/README.md index d04c615..5ddaf8a 100644 --- a/tools/cfspack/README.md +++ b/tools/cfspack/README.md @@ -15,6 +15,9 @@ to the filenames under it. `cfspack` takes an optional second argument, a "fnmatch" pattern. If specified, only files patching the pattern will be included. +If path is a file, a CFS with a single file will be spit and its name will +exclude the directory part of that filename. + The program errors out if a file name is too long (> 26 bytes) or too big (> 0x10000 - 0x20 bytes). diff --git a/tools/cfspack/cfspack.c b/tools/cfspack/cfspack.c index af8b13a..009b067 100644 --- a/tools/cfspack/cfspack.c +++ b/tools/cfspack/cfspack.c @@ -3,12 +3,20 @@ #include #include #include +#include #define BLKSIZE 0x100 #define HEADERSIZE 0x20 #define MAX_FN_LEN 25 // 26 - null char #define MAX_FILE_SIZE (BLKSIZE * 0x100) - HEADERSIZE +int is_regular_file(char *path) +{ + struct stat path_stat; + stat(path, &path_stat); + return S_ISREG(path_stat.st_mode); +} + int spitblock(char *fullpath, char *fn) { FILE *fp = fopen(fullpath, "r"); @@ -124,6 +132,11 @@ int main(int argc, char *argv[]) if (argc == 3) { pattern = argv[2]; } - return spitdir(srcpath, "", pattern); + if (is_regular_file(srcpath)) { + // special case: just one file + return spitblock(srcpath, basename(srcpath)); + } else { + return spitdir(srcpath, "", pattern); + } }