From f7d6b9b58e4e8d979004026b41c1bfd275218fb9 Mon Sep 17 00:00:00 2001 From: inmarket Date: Fri, 7 Feb 2014 18:43:39 +1000 Subject: Bug fixes to GFILE. --- src/gfile/inc_nativefs.c | 28 ++++++++++++++++------------ src/gfile/inc_romfs.c | 20 ++++++++++++++------ tools/file2c/binaries/windows/file2c.exe | Bin 22030 -> 22030 bytes tools/file2c/src/file2c.c | 2 +- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/gfile/inc_nativefs.c b/src/gfile/inc_nativefs.c index 390a885d..4ecb2004 100644 --- a/src/gfile/inc_nativefs.c +++ b/src/gfile/inc_nativefs.c @@ -16,7 +16,7 @@ #include #include #include -#include +//#include static GFILE NativeStdIn; static GFILE NativeStdOut; @@ -50,7 +50,7 @@ static const GFILEVMT FsNativeVMT = { #undef GFILE_CHAINHEAD #define GFILE_CHAINHEAD &FsNativeVMT -static char *flags2mode(char *buf, uint16_t flags) { +static void flags2mode(char *buf, uint16_t flags) { if (flags & GFILEFLG_MUSTEXIST) *buf = 'r'; else if (flags & GFILEFLG_APPEND) @@ -67,32 +67,36 @@ static char *flags2mode(char *buf, uint16_t flags) { *buf++ = 0; } -static bool_t NativeDel(const char *fname) { return remove(fname) ? FALSE : TRUE; } -static bool_t NativeExists(const char *fname) { return access(fname, 0) ? FALSE : TRUE; } +static bool_t NativeDel(const char *fname) { return remove(fname) ? FALSE : TRUE; } +static void NativeClose(GFILE *f) { fclose((FILE *)f->obj); } +static int NativeRead(GFILE *f, void *buf, int size) { return fread(buf, 1, size, (FILE *)f->obj); } +static int NativeWrite(GFILE *f, const void *buf, int size) { return fwrite(buf, 1, size, (FILE *)f->obj); } +static bool_t NativeSetpos(GFILE *f, long int pos) { return fseek((FILE *)f->obj, pos, SEEK_SET) ? FALSE : TRUE; } +static bool_t NativeEof(GFILE *f) { return feof((FILE *)f->obj) ? TRUE : FALSE; } +static bool_t NativeRen(const char *oldname, const char *newname) { return rename(oldname, newname) ? FALSE : TRUE; } +static bool_t NativeExists(const char *fname) { + // We define access this way so we don't have to include which may + // (and does under windows) contain conflicting definitions for types such as uint16_t. + extern int access(const char *pathname, int mode); + return access(fname, 0) ? FALSE : TRUE; +} static long int NativeFilesize(const char *fname) { struct stat st; if (stat(fname, &st)) return -1; return st.st_size; } -static bool_t NativeRen(const char *oldname, const char *newname) { return rename(oldname, newname) ? FALSE : TRUE }; static bool_t NativeOpen(GFILE *f, const char *fname) { FILE *fd; char mode[5]; + flags2mode(mode, f->flags); if (!(fd = fopen(fname, mode))) return FALSE; f->obj = (void *)fd; return TRUE; } -static void NativeClose(GFILE *f) { fclose((FILE *)f->obj); } -static int NativeRead(GFILE *f, void *buf, int size) { return fread(buf, 1, size, (FILE *)f->obj); } -static int NativeWrite(GFILE *f, const void *buf, int size) { return fwrite(buf, 1, size, (FILE *)f->obj); } -static bool_t NativeSetpos(GFILE *f, long int pos) { - return fseek((FILE *)f->obj, pos, SEEK_SET) ? FALSE : TRUE; -} static long int NativeGetsize(GFILE *f) { struct stat st; if (fstat(fileno((FILE *)f->obj), &st)) return -1; return st.st_size; } -static bool_t NativeEof(GFILE *f) { return feof((FILE *)f->obj) ? TRUE : FALSE; } diff --git a/src/gfile/inc_romfs.c b/src/gfile/inc_romfs.c index 8d0e32c1..49c1b173 100644 --- a/src/gfile/inc_romfs.c +++ b/src/gfile/inc_romfs.c @@ -15,11 +15,19 @@ #include +// What directory file formats do we understand +#define ROMFS_DIR_VER_MAX 0x0000 + +// Compression Formats +#define ROMFS_CMP_UNCOMPRESSED 0 + typedef struct ROMFS_DIRENTRY { - const struct ROMFS_DIRENTRY * next; - const char * name; - long int size; - const char * file; + uint16_t ver; // Directory Entry Version + uint16_t cmp; // Compression format + const struct ROMFS_DIRENTRY * next; // The next entry + const char * name; // The file name + long int size; // The file size + const char * file; // The file data } ROMFS_DIRENTRY; #define ROMFS_DIRENTRY_HEAD 0 @@ -48,11 +56,11 @@ static const GFILEVMT FsROMVMT = { #undef GFILE_CHAINHEAD #define GFILE_CHAINHEAD &FsROMVMT -static ROMFS_DIRENTRY *ROMFindFile(const char *fname) { +static const ROMFS_DIRENTRY *ROMFindFile(const char *fname) { const ROMFS_DIRENTRY *p; for(p = FsROMHead; p; p = p->next) { - if (!strcmp(p->name, fname)) + if (p->ver <= ROMFS_DIR_VER_MAX && p->cmp == ROMFS_CMP_UNCOMPRESSED && !strcmp(p->name, fname)) break; } return p; diff --git a/tools/file2c/binaries/windows/file2c.exe b/tools/file2c/binaries/windows/file2c.exe index dc530bf9..28e9a329 100644 Binary files a/tools/file2c/binaries/windows/file2c.exe and b/tools/file2c/binaries/windows/file2c.exe differ diff --git a/tools/file2c/src/file2c.c b/tools/file2c/src/file2c.c index 1c279ff2..f1415fe7 100644 --- a/tools/file2c/src/file2c.c +++ b/tools/file2c/src/file2c.c @@ -195,7 +195,7 @@ size_t i; /* Add the directory entry if required */ if (opt_romdir) { fprintf(f_output, "\n#ifdef ROMFS_DIRENTRY_HEAD\n"); - fprintf(f_output, "\t%s%sROMFS_DIRENTRY %s_dir = { ROMFS_DIRENTRY_HEAD, \"%s\", %u, %s };\n", opt_static, opt_const, opt_arrayname, opt_dirname, totallen, opt_arrayname); + fprintf(f_output, "\t%s%sROMFS_DIRENTRY %s_dir = { 0, 0, ROMFS_DIRENTRY_HEAD, \"%s\", %u, %s };\n", opt_static, opt_const, opt_arrayname, opt_dirname, totallen, opt_arrayname); fprintf(f_output, "\t#undef ROMFS_DIRENTRY_HEAD\n\t#define ROMFS_DIRENTRY_HEAD &%s_dir\n#endif\n", opt_arrayname); } -- cgit v1.2.3