From ba676b23e5b12927524a5f5f42d1822c9916610a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 20 Mar 2012 15:38:12 -0400 Subject: [PATCH] Reworked the error reporting API. Now we use error codes instead of strings. This is based on work originally done by Christoph Nelles. --- docs/TODO.txt | 7 +- src/archiver_dir.c | 23 +- src/archiver_grp.c | 16 +- src/archiver_hog.c | 16 +- src/archiver_iso9660.c | 105 ++++--- src/archiver_lzma.c | 58 ++-- src/archiver_mvl.c | 17 +- src/archiver_qpak.c | 57 ++-- src/archiver_unpacked.c | 38 +-- src/archiver_wad.c | 22 +- src/archiver_zip.c | 204 ++++++------- src/physfs.c | 377 +++++++++++++---------- src/physfs.h | 183 +++++++++++- src/physfs_byteorder.c | 6 +- src/physfs_internal.h | 642 ++-------------------------------------- src/platform_beos.cpp | 3 +- src/platform_macosx.c | 27 +- src/platform_posix.c | 82 +++-- src/platform_unix.c | 14 +- src/platform_windows.c | 169 ++++++----- 20 files changed, 882 insertions(+), 1184 deletions(-) diff --git a/docs/TODO.txt b/docs/TODO.txt index e8d76098..05d1a013 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -14,10 +14,6 @@ From http://icculus.org/pipermail/physfs/2009-March/000698.html ... - Archives formats provided by the implementation. - Write support for various archives. I haven't decided how to do this yet, but I'd like to. -- Replace the existing error strings with something more flexible...right now, - you have to pick a translation at compile time, which isn't too useful. It - might be nice to have real error codes for apps instead of just error - messages for humans, too. - Add an API to expose a file's extended attributes to the application? - Deprecate PHYSFS_setSaneConfig(). It really should have been in the extras directory. @@ -26,7 +22,6 @@ From http://icculus.org/pipermail/physfs/2009-March/000698.html ... From http://icculus.org/pipermail/physfs/2010-January/000821.html ... -- Using error codes instead of error messages - Plugin system for the archive handlers @@ -86,9 +81,9 @@ Other stuff I thought of... - bzip2 support in zip archiver? - rewrite 7zip archiver. - ryanify iso9660 code. -- Examine Chris Nelles's errorcode stuff. - Move archiver_qpak.c code to archiver_unpacked.c? - Cache basedir/userdir results (do we do this already?) +- Reduce the BAIL and GOTO macro use. A lot of these don't add anything. Probably other stuff. Requests and recommendations are welcome. diff --git a/src/archiver_dir.c b/src/archiver_dir.c index ede5a521..cde1e2b7 100644 --- a/src/archiver_dir.c +++ b/src/archiver_dir.c @@ -15,7 +15,7 @@ static char *cvtToDependent(const char *prepend, const char *path, char *buf) { - BAIL_IF_MACRO(buf == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); sprintf(buf, "%s%s", prepend ? prepend : "", path); if (__PHYSFS_platformDirSeparator != '/') @@ -38,7 +38,7 @@ static char *cvtToDependent(const char *prepend, const char *path, char *buf) static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting) { - PHYSFS_Stat statbuf; + PHYSFS_Stat st; const char dirsep = __PHYSFS_platformDirSeparator; char *retval = NULL; const size_t namelen = strlen(name); @@ -46,12 +46,15 @@ static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting) int exists = 0; assert(io == NULL); /* shouldn't create an Io for these. */ - BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &exists, &statbuf), NULL, NULL); - if ((!exists) || (statbuf.filetype != PHYSFS_FILETYPE_DIRECTORY)) - BAIL_MACRO(ERR_NOT_AN_ARCHIVE, NULL); + BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &exists, &st), ERRPASS, NULL); + /* !!! FIXME: the failed Stat() call will BAIL before we check (exists) */ + /* !!! FIXME: ...should we even be checking for existance here...? */ + BAIL_IF_MACRO(!exists, PHYSFS_ERR_NO_SUCH_PATH, NULL); + if (st.filetype != PHYSFS_FILETYPE_DIRECTORY) + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); retval = allocator.Malloc(namelen + seplen + 1); - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(retval == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); strcpy(retval, name); @@ -90,7 +93,7 @@ static PHYSFS_Io *doOpen(dvoid *opaque, const char *name, int existtmp = 0; CVT_TO_DEPENDENT(f, opaque, name); - BAIL_IF_MACRO(f == NULL, NULL, NULL); + BAIL_IF_MACRO(!f, ERRPASS, NULL); if (fileExists == NULL) fileExists = &existtmp; @@ -136,7 +139,7 @@ static int DIR_remove(dvoid *opaque, const char *name) char *f; CVT_TO_DEPENDENT(f, opaque, name); - BAIL_IF_MACRO(f == NULL, NULL, 0); + BAIL_IF_MACRO(!f, ERRPASS, 0); retval = __PHYSFS_platformDelete(f); __PHYSFS_smallFree(f); return retval; @@ -149,7 +152,7 @@ static int DIR_mkdir(dvoid *opaque, const char *name) char *f; CVT_TO_DEPENDENT(f, opaque, name); - BAIL_IF_MACRO(f == NULL, NULL, 0); + BAIL_IF_MACRO(!f, ERRPASS, 0); retval = __PHYSFS_platformMkDir(f); __PHYSFS_smallFree(f); return retval; @@ -169,7 +172,7 @@ static int DIR_stat(dvoid *opaque, const char *name, int *exists, char *d; CVT_TO_DEPENDENT(d, opaque, name); - BAIL_IF_MACRO(d == NULL, NULL, 0); + BAIL_IF_MACRO(!d, ERRPASS, 0); retval = __PHYSFS_platformStat(d, exists, stat); __PHYSFS_smallFree(d); return retval; diff --git a/src/archiver_grp.c b/src/archiver_grp.c index 2e29cb1f..36838ab8 100644 --- a/src/archiver_grp.c +++ b/src/archiver_grp.c @@ -37,14 +37,14 @@ static UNPKentry *grpLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 fileCount) char *ptr = NULL; entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount); - BAIL_IF_MACRO(entries == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); location += (16 * fileCount); for (entry = entries; fileCount > 0; fileCount--, entry++) { - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 12), NULL, failed); - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), NULL, failed); + GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 12), ERRPASS, failed); + GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), ERRPASS, failed); entry->name[12] = '\0'; /* name isn't null-terminated in file. */ if ((ptr = strchr(entry->name, ' ')) != NULL) *ptr = '\0'; /* trim extra spaces. */ @@ -70,17 +70,17 @@ static void *GRP_openArchive(PHYSFS_Io *io, const char *name, int forWriting) assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, 0); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, sizeof (buf)), ERRPASS, NULL); if (memcmp(buf, "KenSilverman", sizeof (buf)) != 0) - BAIL_MACRO(ERR_NOT_AN_ARCHIVE, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof (count)), NULL, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof(count)), ERRPASS, NULL); count = PHYSFS_swapULE32(count); entries = grpLoadEntries(io, count); - BAIL_IF_MACRO(entries == NULL, NULL, NULL); + BAIL_IF_MACRO(!entries, ERRPASS, NULL); return UNPK_openArchive(io, entries, count); } /* GRP_openArchive */ diff --git a/src/archiver_hog.c b/src/archiver_hog.c index 2eae5699..9441cea8 100644 --- a/src/archiver_hog.c +++ b/src/archiver_hog.c @@ -48,13 +48,13 @@ static UNPKentry *hogLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 *_entCount) { entCount++; ptr = allocator.Realloc(ptr, sizeof (UNPKentry) * entCount); - GOTO_IF_MACRO(ptr == NULL, ERR_OUT_OF_MEMORY, failed); + GOTO_IF_MACRO(ptr == NULL, PHYSFS_ERR_OUT_OF_MEMORY, failed); entries = (UNPKentry *) ptr; entry = &entries[entCount-1]; - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 13), NULL, failed); + GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 13), ERRPASS, failed); pos += 13; - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &size, 4), NULL, failed); + GOTO_IF_MACRO(!__PHYSFS_readAll(io, &size, 4), ERRPASS, failed); pos += 4; entry->size = PHYSFS_swapULE32(size); @@ -62,7 +62,7 @@ static UNPKentry *hogLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 *_entCount) pos += size; /* skip over entry */ - GOTO_IF_MACRO(!io->seek(io, pos), NULL, failed); + GOTO_IF_MACRO(!io->seek(io, pos), ERRPASS, failed); } /* while */ *_entCount = entCount; @@ -81,12 +81,12 @@ static void *HOG_openArchive(PHYSFS_Io *io, const char *name, int forWriting) UNPKentry *entries = NULL; assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, 3), NULL, 0); - BAIL_IF_MACRO(memcmp(buf, "DHF", 3) != 0, ERR_NOT_AN_ARCHIVE, NULL); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, 3), ERRPASS, NULL); + BAIL_IF_MACRO(memcmp(buf, "DHF", 3) != 0, PHYSFS_ERR_UNSUPPORTED, NULL); entries = hogLoadEntries(io, &count); - BAIL_IF_MACRO(entries == NULL, NULL, NULL); + BAIL_IF_MACRO(!entries, ERRPASS, NULL); return UNPK_openArchive(io, entries, count); } /* HOG_openArchive */ diff --git a/src/archiver_iso9660.c b/src/archiver_iso9660.c index 68156e36..e65605be 100644 --- a/src/archiver_iso9660.c +++ b/src/archiver_iso9660.c @@ -291,8 +291,8 @@ static int iso_extractfilenameISO(ISO9660FileDescriptor *descriptor, for(;pos < descriptor->filenamelen; pos++) if (descriptor->filename[pos] == ';') lastfound = pos; - BAIL_IF_MACRO(lastfound < 1, ERR_BAD_FILENAME, -1); - BAIL_IF_MACRO(lastfound == (descriptor->filenamelen -1), ERR_BAD_FILENAME, -1); + BAIL_IF_MACRO(lastfound < 1, PHYSFS_ERR_NO_SUCH_PATH /* !!! FIXME: PHYSFS_ERR_BAD_FILENAME */, -1); + BAIL_IF_MACRO(lastfound == (descriptor->filenamelen -1), PHYSFS_ERR_NO_SUCH_PATH /* !!! PHYSFS_ERR_BAD_FILENAME */, -1); strncpy(filename, descriptor->filename, lastfound); if (filename[lastfound - 1] == '.') filename[lastfound - 1] = '\0'; /* consume trailing ., as done in all implementations */ @@ -344,16 +344,15 @@ static int iso_extractfilename(ISO9660Handle *handle, static int iso_readimage(ISO9660Handle *handle, PHYSFS_uint64 where, void *buffer, PHYSFS_uint64 len) { - BAIL_IF_MACRO(!__PHYSFS_platformGrabMutex(handle->mutex), - ERR_LOCK_VIOLATION, -1); + BAIL_IF_MACRO(!__PHYSFS_platformGrabMutex(handle->mutex), ERRPASS, -1); int rc = -1; if (where != handle->currpos) - GOTO_IF_MACRO(!handle->io->seek(handle->io,where), NULL, unlockme); + GOTO_IF_MACRO(!handle->io->seek(handle->io,where), ERRPASS, unlockme); rc = handle->io->read(handle->io, buffer, len); if (rc == -1) { handle->currpos = (PHYSFS_uint64) -1; - GOTO_MACRO(NULL, unlockme); + goto unlockme; } /* if */ handle->currpos += rc; @@ -369,16 +368,16 @@ static PHYSFS_sint64 iso_readfiledescriptor(ISO9660Handle *handle, { PHYSFS_sint64 rc = iso_readimage(handle, where, descriptor, sizeof (descriptor->recordlen)); - BAIL_IF_MACRO(rc == -1, NULL, -1); - BAIL_IF_MACRO(rc != 1, ERR_CORRUPTED, -1); + BAIL_IF_MACRO(rc == -1, ERRPASS, -1); + BAIL_IF_MACRO(rc != 1, PHYSFS_ERR_CORRUPT, -1); if (descriptor->recordlen == 0) return 0; /* fill bytes at the end of a sector */ rc = iso_readimage(handle, where + 1, &descriptor->extattributelen, descriptor->recordlen - sizeof(descriptor->recordlen)); - BAIL_IF_MACRO(rc == -1, NULL, -1); - BAIL_IF_MACRO(rc != 1, ERR_CORRUPTED, -1); + BAIL_IF_MACRO(rc == -1, ERRPASS, -1); + BAIL_IF_MACRO(rc != 1, PHYSFS_ERR_CORRUPT, -1); return 0; } /* iso_readfiledescriptor */ @@ -417,7 +416,7 @@ static int iso_find_dir_entry(ISO9660Handle *handle,const char *path, iso_extractsubpath(mypath, &subpath); while (1) { - BAIL_IF_MACRO(iso_readfiledescriptor(handle, readpos, descriptor), NULL, -1); + BAIL_IF_MACRO(iso_readfiledescriptor(handle, readpos, descriptor), ERRPASS, -1); /* recordlen = 0 -> no more entries or fill entry */ if (!descriptor->recordlen) @@ -438,7 +437,7 @@ static int iso_find_dir_entry(ISO9660Handle *handle,const char *path, BAIL_IF_MACRO( iso_extractfilename(handle, descriptor, filename, &version), - NULL, -1); + ERRPASS, -1); if (strcmp(filename, mypath) == 0) { @@ -481,7 +480,7 @@ static int ISO9660_flush(PHYSFS_Io *io) { return 1; /* no write support. */ } static PHYSFS_Io *ISO9660_duplicate(PHYSFS_Io *_io) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); /* !!! FIXME: write me. */ + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); /* !!! FIXME: write me. */ } /* ISO9660_duplicate */ @@ -502,7 +501,7 @@ static PHYSFS_sint64 ISO9660_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len) static PHYSFS_sint64 ISO9660_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 l) { - BAIL_MACRO(ERR_NOT_SUPPORTED, -1); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, -1); } /* ISO9660_write */ @@ -552,37 +551,37 @@ static void *ISO9660_openArchive(PHYSFS_Io *io, const char *filename, int forWri assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); /* Skip system area to magic number in Volume descriptor */ - BAIL_IF_MACRO(!io->seek(io, 32769), NULL, NULL); - BAIL_IF_MACRO(!io->read(io, magicnumber, 5) != 5, NULL, NULL); + BAIL_IF_MACRO(!io->seek(io, 32769), ERRPASS, NULL); + BAIL_IF_MACRO(!io->read(io, magicnumber, 5) != 5, ERRPASS, NULL); if (memcmp(magicnumber, "CD001", 6) != 0) - BAIL_MACRO(ERR_NOT_AN_ARCHIVE, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); handle = allocator.Malloc(sizeof(ISO9660Handle)); - GOTO_IF_MACRO(!handle, ERR_OUT_OF_MEMORY, errorcleanup); + GOTO_IF_MACRO(!handle, PHYSFS_ERR_OUT_OF_MEMORY, errorcleanup); handle->path = 0; handle->mutex= 0; handle->io = NULL; handle->path = allocator.Malloc(strlen(filename) + 1); - GOTO_IF_MACRO(!handle->path, ERR_OUT_OF_MEMORY, errorcleanup); + GOTO_IF_MACRO(!handle->path, PHYSFS_ERR_OUT_OF_MEMORY, errorcleanup); strcpy(handle->path, filename); handle->mutex = __PHYSFS_platformCreateMutex(); - GOTO_IF_MACRO(!handle->mutex, "Cannot create Mutex", errorcleanup); + GOTO_IF_MACRO(!handle->mutex, ERRPASS, errorcleanup); handle->io = io; /* seek Primary Volume Descriptor */ - GOTO_IF_MACRO(!io->seek(io, 32768), ERR_SEEK_ERROR, errorcleanup); + GOTO_IF_MACRO(!io->seek(io, 32768), PHYSFS_ERR_IO, errorcleanup); while (1) { ISO9660VolumeDescriptor descriptor; - GOTO_IF_MACRO(io->read(io, &descriptor, sizeof(ISO9660VolumeDescriptor)) != sizeof(ISO9660VolumeDescriptor), "Cannot read from image", errorcleanup); - GOTO_IF_MACRO(strncmp(descriptor.identifier, "CD001", 5) != 0, ERR_NOT_AN_ARCHIVE, errorcleanup); + GOTO_IF_MACRO(io->read(io, &descriptor, sizeof(ISO9660VolumeDescriptor)) != sizeof(ISO9660VolumeDescriptor), PHYSFS_ERR_IO, errorcleanup); + GOTO_IF_MACRO(strncmp(descriptor.identifier, "CD001", 5) != 0, PHYSFS_ERR_UNSUPPORTED, errorcleanup); if (descriptor.type == 255) { @@ -590,7 +589,7 @@ static void *ISO9660_openArchive(PHYSFS_Io *io, const char *filename, int forWri if (founddescriptor) return handle; /* ok, we've found one volume descriptor */ else - GOTO_MACRO(ERR_CORRUPTED, errorcleanup); + GOTO_MACRO(PHYSFS_ERR_CORRUPT, errorcleanup); } /* if */ if (descriptor.type == 1 && !founddescriptor) { @@ -624,7 +623,7 @@ static void *ISO9660_openArchive(PHYSFS_Io *io, const char *filename, int forWri } /* if */ } /* while */ - GOTO_MACRO(ERR_CORRUPTED, errorcleanup); /* not found. */ + GOTO_MACRO(PHYSFS_ERR_CORRUPT, errorcleanup); /* not found. */ errorcleanup: if (handle) @@ -674,8 +673,8 @@ static PHYSFS_uint32 iso_file_read_mem(ISO9660FileHandle *filehandle, static int iso_file_seek_mem(ISO9660FileHandle *fhandle, PHYSFS_sint64 offset) { - BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); - BAIL_IF_MACRO(offset >= fhandle->filesize, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(offset < 0, PHYSFS_ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(offset >= fhandle->filesize, PHYSFS_ERR_PAST_EOF, 0); fhandle->currpos = offset; return 0; @@ -698,10 +697,10 @@ static PHYSFS_uint32 iso_file_read_foreign(ISO9660FileHandle *filehandle, len = bytesleft; const PHYSFS_sint64 rc = filehandle->io->read(filehandle->io, buffer, len); - BAIL_IF_MACRO(rc == -1, NULL, -1); + BAIL_IF_MACRO(rc == -1, ERRPASS, -1); filehandle->currpos += rc; /* i trust my internal book keeping */ - BAIL_IF_MACRO(rc < len, ERR_CORRUPTED, -1); + BAIL_IF_MACRO(rc < len, PHYSFS_ERR_CORRUPT, -1); return rc; } /* iso_file_read_foreign */ @@ -709,11 +708,11 @@ static PHYSFS_uint32 iso_file_read_foreign(ISO9660FileHandle *filehandle, static int iso_file_seek_foreign(ISO9660FileHandle *fhandle, PHYSFS_sint64 offset) { - BAIL_IF_MACRO(offset < 0, ERR_INVALID_ARGUMENT, 0); - BAIL_IF_MACRO(offset >= fhandle->filesize, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(offset < 0, PHYSFS_ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(offset >= fhandle->filesize, PHYSFS_ERR_PAST_EOF, 0); PHYSFS_sint64 pos = fhandle->startblock * 2048 + offset; - BAIL_IF_MACRO(!fhandle->io->seek(fhandle->io, pos), NULL, -1); + BAIL_IF_MACRO(!fhandle->io->seek(fhandle->io, pos), ERRPASS, -1); fhandle->currpos = offset; return 0; @@ -730,11 +729,11 @@ static void iso_file_close_foreign(ISO9660FileHandle *fhandle) static int iso_file_open_mem(ISO9660Handle *handle, ISO9660FileHandle *fhandle) { fhandle->cacheddata = allocator.Malloc(fhandle->filesize); - BAIL_IF_MACRO(!fhandle->cacheddata, ERR_OUT_OF_MEMORY, -1); + BAIL_IF_MACRO(!fhandle->cacheddata, PHYSFS_ERR_OUT_OF_MEMORY, -1); int rc = iso_readimage(handle, fhandle->startblock * 2048, fhandle->cacheddata, fhandle->filesize); - GOTO_IF_MACRO(rc < 0, NULL, freemem); - GOTO_IF_MACRO(rc == 0, ERR_CORRUPTED, freemem); + GOTO_IF_MACRO(rc < 0, ERRPASS, freemem); + GOTO_IF_MACRO(rc == 0, PHYSFS_ERR_CORRUPT, freemem); fhandle->read = iso_file_read_mem; fhandle->seek = iso_file_seek_mem; @@ -752,9 +751,9 @@ static int iso_file_open_foreign(ISO9660Handle *handle, { int rc; fhandle->io = __PHYSFS_createNativeIo(handle->path, 'r'); - BAIL_IF_MACRO(!fhandle->io, NULL, -1); + BAIL_IF_MACRO(!fhandle->io, ERRPASS, -1); rc = fhandle->io->seek(fhandle->io, fhandle->startblock * 2048); - GOTO_IF_MACRO(!rc, NULL, closefile); + GOTO_IF_MACRO(!rc, ERRPASS, closefile); fhandle->read = iso_file_read_foreign; fhandle->seek = iso_file_seek_foreign; @@ -776,16 +775,16 @@ static PHYSFS_Io *ISO9660_openRead(dvoid *opaque, const char *filename, int *exi int rc; fhandle = allocator.Malloc(sizeof(ISO9660FileHandle)); - BAIL_IF_MACRO(fhandle == 0, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(fhandle == 0, PHYSFS_ERR_OUT_OF_MEMORY, NULL); fhandle->cacheddata = 0; retval = allocator.Malloc(sizeof(PHYSFS_Io)); - GOTO_IF_MACRO(retval == 0, ERR_OUT_OF_MEMORY, errorhandling); + GOTO_IF_MACRO(retval == 0, PHYSFS_ERR_OUT_OF_MEMORY, errorhandling); /* find file descriptor */ rc = iso_find_dir_entry(handle, filename, &descriptor, exists); - GOTO_IF_MACRO(rc, NULL, errorhandling); - GOTO_IF_MACRO(!*exists, ERR_NO_SUCH_FILE, errorhandling); + GOTO_IF_MACRO(rc, ERRPASS, errorhandling); + GOTO_IF_MACRO(!*exists, PHYSFS_ERR_NO_SUCH_PATH, errorhandling); fhandle->startblock = descriptor.extentpos + descriptor.extattributelen; fhandle->filesize = descriptor.datalen; @@ -798,7 +797,7 @@ static PHYSFS_Io *ISO9660_openRead(dvoid *opaque, const char *filename, int *exi rc = iso_file_open_mem(handle, fhandle); else rc = iso_file_open_foreign(handle, fhandle); - GOTO_IF_MACRO(rc, NULL, errorhandling); + GOTO_IF_MACRO(rc, ERRPASS, errorhandling); memcpy(retval, &ISO9660_Io, sizeof (PHYSFS_Io)); retval->opaque = fhandle; @@ -837,9 +836,9 @@ static void ISO9660_enumerateFiles(dvoid *opaque, const char *dname, { printf("pfad %s\n",dname); int exists = 0; - BAIL_IF_MACRO(iso_find_dir_entry(handle,dname, &descriptor, &exists), NULL,); - BAIL_IF_MACRO(exists == 0, NULL, ); - BAIL_IF_MACRO(!descriptor.flags.directory, NULL,); + BAIL_IF_MACRO(iso_find_dir_entry(handle,dname, &descriptor, &exists), ERRPASS,); + BAIL_IF_MACRO(!exists, ERRPASS, ); + BAIL_IF_MACRO(!descriptor.flags.directory, ERRPASS,); readpos = descriptor.extentpos * 2048; end_of_dir = readpos + descriptor.datalen; @@ -847,7 +846,7 @@ static void ISO9660_enumerateFiles(dvoid *opaque, const char *dname, while (1) { - BAIL_IF_MACRO(iso_readfiledescriptor(handle, readpos, &descriptor), NULL, ); + BAIL_IF_MACRO(iso_readfiledescriptor(handle, readpos, &descriptor), ERRPASS, ); /* recordlen = 0 -> no more entries or fill entry */ if (!descriptor.recordlen) @@ -879,7 +878,7 @@ static int ISO9660_stat(dvoid *opaque, const char *name, int *exists, ISO9660Handle *handle = (ISO9660Handle*) opaque; ISO9660FileDescriptor descriptor; ISO9660ExtAttributeRec extattr; - BAIL_IF_MACRO(iso_find_dir_entry(handle, name, &descriptor, exists), NULL, -1); + BAIL_IF_MACRO(iso_find_dir_entry(handle, name, &descriptor, exists), ERRPASS, -1); if (!*exists) return 0; @@ -889,7 +888,7 @@ static int ISO9660_stat(dvoid *opaque, const char *name, int *exists, if (descriptor.extattributelen) { BAIL_IF_MACRO(iso_read_ext_attributes(handle, - descriptor.extentpos, &extattr), NULL, -1); + descriptor.extentpos, &extattr), ERRPASS, -1); stat->createtime = iso_volume_mktime(&extattr.create_time); stat->modtime = iso_volume_mktime(&extattr.mod_time); stat->accesstime = iso_volume_mktime(&extattr.mod_time); @@ -922,25 +921,25 @@ static int ISO9660_stat(dvoid *opaque, const char *name, int *exists, static PHYSFS_Io *ISO9660_openWrite(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* ISO9660_openWrite */ static PHYSFS_Io *ISO9660_openAppend(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* ISO9660_openAppend */ static int ISO9660_remove(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* ISO9660_remove */ static int ISO9660_mkdir(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* ISO9660_mkdir */ diff --git a/src/archiver_lzma.c b/src/archiver_lzma.c index 18197b40..234c4961 100644 --- a/src/archiver_lzma.c +++ b/src/archiver_lzma.c @@ -205,7 +205,7 @@ static LZMAfile * lzma_find_file(const LZMAarchive *archive, const char *name) { LZMAfile *file = bsearch(name, archive->files, archive->db.Database.NumFiles, sizeof(*archive->files), lzma_file_cmp_stdlib); /* FIXME: Should become __PHYSFS_search!!! */ - BAIL_IF_MACRO(file == NULL, ERR_NO_SUCH_FILE, NULL); + BAIL_IF_MACRO(file == NULL, PHYSFS_ERR_NO_SUCH_PATH, NULL); return file; } /* lzma_find_file */ @@ -291,25 +291,25 @@ static int lzma_err(SZ_RESULT rc) case SZ_OK: /* Same as LZMA_RESULT_OK */ break; case SZE_DATA_ERROR: /* Same as LZMA_RESULT_DATA_ERROR */ - __PHYSFS_setError(ERR_DATA_ERROR); + __PHYSFS_setError(PHYSFS_ERR_CORRUPT); /*!!!FIXME: was "PHYSFS_ERR_DATA_ERROR" */ break; case SZE_OUTOFMEMORY: - __PHYSFS_setError(ERR_OUT_OF_MEMORY); + __PHYSFS_setError(PHYSFS_ERR_OUT_OF_MEMORY); break; case SZE_CRC_ERROR: - __PHYSFS_setError(ERR_CORRUPTED); + __PHYSFS_setError(PHYSFS_ERR_CORRUPT); break; case SZE_NOTIMPL: - __PHYSFS_setError(ERR_NOT_IMPLEMENTED); + __PHYSFS_setError(PHYSFS_ERR_UNSUPPORTED); break; case SZE_FAIL: - __PHYSFS_setError(ERR_UNKNOWN_ERROR); /* !!! FIXME: right? */ + __PHYSFS_setError(PHYSFS_ERR_OTHER_ERROR); /* !!! FIXME: right? */ break; case SZE_ARCHIVE_ERROR: - __PHYSFS_setError(ERR_CORRUPTED); /* !!! FIXME: right? */ + __PHYSFS_setError(PHYSFS_ERR_CORRUPT); /* !!! FIXME: right? */ break; default: - __PHYSFS_setError(ERR_UNKNOWN_ERROR); + __PHYSFS_setError(PHYSFS_ERR_OTHER_ERROR); } /* switch */ return rc; @@ -324,8 +324,8 @@ static PHYSFS_sint64 LZMA_read(PHYSFS_Io *io, void *outBuf, PHYSFS_uint64 len) const size_t remainingSize = file->item->Size - file->position; size_t fileSize = 0; - BAIL_IF_MACRO(wantedSize == 0, NULL, 0); /* quick rejection. */ - BAIL_IF_MACRO(remainingSize == 0, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(wantedSize == 0, ERRPASS, 0); /* quick rejection. */ + BAIL_IF_MACRO(remainingSize == 0, PHYSFS_ERR_PAST_EOF, 0); if (wantedSize > remainingSize) wantedSize = remainingSize; @@ -364,7 +364,7 @@ static PHYSFS_sint64 LZMA_read(PHYSFS_Io *io, void *outBuf, PHYSFS_uint64 len) static PHYSFS_sint64 LZMA_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len) { - BAIL_MACRO(ERR_NOT_SUPPORTED, -1); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, -1); } /* LZMA_write */ @@ -379,7 +379,7 @@ static int LZMA_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) { LZMAfile *file = (LZMAfile *) io->opaque; - BAIL_IF_MACRO(offset > file->item->Size, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(offset > file->item->Size, PHYSFS_ERR_PAST_EOF, 0); file->position = offset; /* We only use a virtual position... */ @@ -398,7 +398,7 @@ static PHYSFS_Io *LZMA_duplicate(PHYSFS_Io *_io) { /* !!! FIXME: this archiver needs to be reworked to allow multiple * !!! FIXME: opens before we worry about duplication. */ - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* LZMA_duplicate */ @@ -447,15 +447,15 @@ static void *LZMA_openArchive(PHYSFS_Io *io, const char *name, int forWriting) assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); if (io->read(io, sig, k7zSignatureSize) != k7zSignatureSize) - BAIL_MACRO(NULL, 0); - BAIL_IF_MACRO(!TestSignatureCandidate(sig), ERR_NOT_AN_ARCHIVE, NULL); - BAIL_IF_MACRO(!io->seek(io, 0), NULL, NULL); + return 0; + BAIL_IF_MACRO(!TestSignatureCandidate(sig), PHYSFS_ERR_UNSUPPORTED, NULL); + BAIL_IF_MACRO(!io->seek(io, 0), ERRPASS, NULL); archive = (LZMAarchive *) allocator.Malloc(sizeof (LZMAarchive)); - BAIL_IF_MACRO(archive == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(archive == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); lzma_archive_init(archive); archive->stream.io = io; @@ -478,7 +478,7 @@ static void *LZMA_openArchive(PHYSFS_Io *io, const char *name, int forWriting) { SzArDbExFree(&archive->db, SzFreePhysicsFS); lzma_archive_exit(archive); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* @@ -493,7 +493,7 @@ static void *LZMA_openArchive(PHYSFS_Io *io, const char *name, int forWriting) { SzArDbExFree(&archive->db, SzFreePhysicsFS); lzma_archive_exit(archive); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* @@ -506,7 +506,7 @@ static void *LZMA_openArchive(PHYSFS_Io *io, const char *name, int forWriting) { SzArDbExFree(&archive->db, SzFreePhysicsFS); lzma_archive_exit(archive); - BAIL_MACRO(ERR_UNKNOWN_ERROR, NULL); + BAIL_MACRO(PHYSFS_ERR_OTHER_ERROR, NULL); } return archive; @@ -551,7 +551,7 @@ static void LZMA_enumerateFiles(dvoid *opaque, const char *dname, file = archive->files; } - BAIL_IF_MACRO(file == NULL, ERR_NO_SUCH_FILE, ); + BAIL_IF_MACRO(file == NULL, PHYSFS_ERR_NO_SUCH_PATH, ); while (file < lastFile) { @@ -582,14 +582,14 @@ static PHYSFS_Io *LZMA_openRead(dvoid *opaque, const char *name, int *fileExists PHYSFS_Io *io = NULL; *fileExists = (file != NULL); - BAIL_IF_MACRO(file == NULL, ERR_NO_SUCH_FILE, NULL); - BAIL_IF_MACRO(file->folder == NULL, ERR_NOT_A_FILE, NULL); + BAIL_IF_MACRO(file == NULL, PHYSFS_ERR_NO_SUCH_PATH, NULL); + BAIL_IF_MACRO(file->folder == NULL, PHYSFS_ERR_NOT_A_FILE, NULL); file->position = 0; file->folder->references++; /* Increase refcount for automatic cleanup... */ io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - BAIL_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(io == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); memcpy(io, &LZMA_Io, sizeof (*io)); io->opaque = file; @@ -599,13 +599,13 @@ static PHYSFS_Io *LZMA_openRead(dvoid *opaque, const char *name, int *fileExists static PHYSFS_Io *LZMA_openWrite(dvoid *opaque, const char *filename) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* LZMA_openWrite */ static PHYSFS_Io *LZMA_openAppend(dvoid *opaque, const char *filename) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* LZMA_openAppend */ @@ -629,13 +629,13 @@ static void LZMA_dirClose(dvoid *opaque) static int LZMA_remove(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* LZMA_remove */ static int LZMA_mkdir(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* LZMA_mkdir */ static int LZMA_stat(dvoid *opaque, const char *filename, int *exists, diff --git a/src/archiver_mvl.c b/src/archiver_mvl.c index 1f158645..20352181 100644 --- a/src/archiver_mvl.c +++ b/src/archiver_mvl.c @@ -39,14 +39,14 @@ static UNPKentry *mvlLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 fileCount) UNPKentry *entry = NULL; entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount); - BAIL_IF_MACRO(entries == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); location += (17 * fileCount); for (entry = entries; fileCount > 0; fileCount--, entry++) { - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 13), NULL, failed); - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), NULL, failed); + if (!__PHYSFS_readAll(io, &entry->name, 13)) goto failed; + if (!__PHYSFS_readAll(io, &entry->size, 4)) goto failed; entry->size = PHYSFS_swapULE32(entry->size); entry->startPos = location; location += entry->size; @@ -67,15 +67,14 @@ static void *MVL_openArchive(PHYSFS_Io *io, const char *name, int forWriting) UNPKentry *entries = NULL; assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, 4), NULL, NULL); - BAIL_IF_MACRO(memcmp(buf, "DMVL", 4) != 0, ERR_NOT_AN_ARCHIVE, NULL); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof (count)), NULL, NULL); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, 4), ERRPASS, NULL); + BAIL_IF_MACRO(memcmp(buf, "DMVL", 4) != 0, PHYSFS_ERR_UNSUPPORTED, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof(count)), ERRPASS, NULL); count = PHYSFS_swapULE32(count); entries = mvlLoadEntries(io, count); - BAIL_IF_MACRO(entries == NULL, NULL, NULL); - return UNPK_openArchive(io, entries, count); + return (!entries) ? NULL : UNPK_openArchive(io, entries, count); } /* MVL_openArchive */ diff --git a/src/archiver_qpak.c b/src/archiver_qpak.c index 871ace87..db6ab91c 100644 --- a/src/archiver_qpak.c +++ b/src/archiver_qpak.c @@ -98,7 +98,7 @@ static PHYSFS_sint64 QPAK_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len) static PHYSFS_sint64 QPAK_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len) { - BAIL_MACRO(ERR_NOT_SUPPORTED, -1); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, -1); } /* QPAK_write */ @@ -114,7 +114,7 @@ static int QPAK_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) const QPAKentry *entry = finfo->entry; int rc; - BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(offset >= entry->size, PHYSFS_ERR_PAST_EOF, 0); rc = finfo->io->seek(finfo->io, entry->startPos + offset); if (rc) finfo->curPos = (PHYSFS_uint32) offset; @@ -136,11 +136,11 @@ static PHYSFS_Io *QPAK_duplicate(PHYSFS_Io *_io) PHYSFS_Io *io = NULL; PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); QPAKfileinfo *finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo)); - GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, QPAK_duplicate_failed); - GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, QPAK_duplicate_failed); + GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, QPAK_duplicate_failed); + GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, QPAK_duplicate_failed); io = origfinfo->io->duplicate(origfinfo->io); - GOTO_IF_MACRO(io == NULL, NULL, QPAK_duplicate_failed); + GOTO_IF_MACRO(!io, ERRPASS, QPAK_duplicate_failed); finfo->io = io; finfo->entry = origfinfo->entry; finfo->curPos = 0; @@ -215,13 +215,13 @@ static int qpak_load_entries(QPAKinfo *info) QPAKentry *entry; info->entries = (QPAKentry*) allocator.Malloc(sizeof(QPAKentry)*fileCount); - BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(info->entries == NULL, PHYSFS_ERR_OUT_OF_MEMORY, 0); for (entry = info->entries; fileCount > 0; fileCount--, entry++) { - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 56), NULL, 0); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->startPos, 4), NULL, 0); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), NULL, 0); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 56), ERRPASS, 0); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->startPos, 4), ERRPASS, 0); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), ERRPASS, 0); entry->size = PHYSFS_swapULE32(entry->size); entry->startPos = PHYSFS_swapULE32(entry->startPos); } /* for */ @@ -240,25 +240,26 @@ static void *QPAK_openArchive(PHYSFS_Io *io, const char *name, int forWriting) assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), NULL, NULL); - BAIL_IF_MACRO(PHYSFS_swapULE32(val) != QPAK_SIG, ERR_NOT_AN_ARCHIVE, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL); + if (PHYSFS_swapULE32(val) != QPAK_SIG) + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), NULL, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL); pos = PHYSFS_swapULE32(val); /* directory table offset. */ - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), NULL, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &val, 4), ERRPASS, NULL); count = PHYSFS_swapULE32(val); /* corrupted archive? */ - BAIL_IF_MACRO((count % 64) != 0, ERR_CORRUPTED, NULL); + BAIL_IF_MACRO((count % 64) != 0, PHYSFS_ERR_CORRUPT, NULL); count /= 64; - BAIL_IF_MACRO(!io->seek(io, pos), NULL, NULL); + BAIL_IF_MACRO(!io->seek(io, pos), ERRPASS, NULL); info = (QPAKinfo *) allocator.Malloc(sizeof (QPAKinfo)); - BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(info == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); memset(info, '\0', sizeof (QPAKinfo)); info->io = io; info->entryCount = count; @@ -439,7 +440,7 @@ static QPAKentry *qpak_find_entry(const QPAKinfo *info, const char *path, if (isDir != NULL) *isDir = 0; - BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); + BAIL_MACRO(PHYSFS_ERR_NO_SUCH_PATH, NULL); } /* qpak_find_entry */ @@ -453,21 +454,21 @@ static PHYSFS_Io *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists) entry = qpak_find_entry(info, fnm, &isDir); *fileExists = ((entry != NULL) || (isDir)); - BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL); - BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL); + BAIL_IF_MACRO(isDir, PHYSFS_ERR_NOT_A_FILE, NULL); + BAIL_IF_MACRO(entry == NULL, PHYSFS_ERR_NO_SUCH_PATH, NULL); finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo)); - BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(finfo == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL); finfo->io = info->io->duplicate(info->io); - GOTO_IF_MACRO(finfo->io == NULL, NULL, QPAK_openRead_failed); + GOTO_IF_MACRO(finfo->io == NULL, ERRPASS, QPAK_openRead_failed); if (!finfo->io->seek(finfo->io, entry->startPos)) - GOTO_MACRO(NULL, QPAK_openRead_failed); + goto QPAK_openRead_failed; finfo->curPos = 0; finfo->entry = entry; io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - GOTO_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, QPAK_openRead_failed); + GOTO_IF_MACRO(io == NULL, PHYSFS_ERR_OUT_OF_MEMORY, QPAK_openRead_failed); memcpy(io, &QPAK_Io, sizeof (PHYSFS_Io)); io->opaque = finfo; @@ -490,25 +491,25 @@ static PHYSFS_Io *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists) static PHYSFS_Io *QPAK_openWrite(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* QPAK_openWrite */ static PHYSFS_Io *QPAK_openAppend(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* QPAK_openAppend */ static int QPAK_remove(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* QPAK_remove */ static int QPAK_mkdir(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* QPAK_mkdir */ diff --git a/src/archiver_unpacked.c b/src/archiver_unpacked.c index ec60c44e..7492a8d4 100644 --- a/src/archiver_unpacked.c +++ b/src/archiver_unpacked.c @@ -62,7 +62,7 @@ static PHYSFS_sint64 UNPK_read(PHYSFS_Io *io, void *buffer, PHYSFS_uint64 len) static PHYSFS_sint64 UNPK_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len) { - BAIL_MACRO(ERR_NOT_SUPPORTED, -1); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, -1); } /* UNPK_write */ @@ -78,7 +78,7 @@ static int UNPK_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) const UNPKentry *entry = finfo->entry; int rc; - BAIL_IF_MACRO(offset >= entry->size, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(offset >= entry->size, PHYSFS_ERR_PAST_EOF, 0); rc = finfo->io->seek(finfo->io, entry->startPos + offset); if (rc) finfo->curPos = (PHYSFS_uint32) offset; @@ -100,11 +100,11 @@ static PHYSFS_Io *UNPK_duplicate(PHYSFS_Io *_io) PHYSFS_Io *io = NULL; PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); UNPKfileinfo *finfo = (UNPKfileinfo *) allocator.Malloc(sizeof (UNPKfileinfo)); - GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, UNPK_duplicate_failed); - GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, UNPK_duplicate_failed); + GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_duplicate_failed); + GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_duplicate_failed); io = origfinfo->io->duplicate(origfinfo->io); - GOTO_IF_MACRO(io == NULL, NULL, UNPK_duplicate_failed); + if (!io) goto UNPK_duplicate_failed; finfo->io = io; finfo->entry = origfinfo->entry; finfo->curPos = 0; @@ -171,8 +171,8 @@ static void entrySwap(void *_a, PHYSFS_uint32 one, PHYSFS_uint32 two) void UNPK_enumerateFiles(dvoid *opaque, const char *dname, - int omitSymLinks, PHYSFS_EnumFilesCallback cb, - const char *origdir, void *callbackdata) + int omitSymLinks, PHYSFS_EnumFilesCallback cb, + const char *origdir, void *callbackdata) { /* no directories in UNPK files. */ if (*dname == '\0') @@ -208,7 +208,7 @@ static UNPKentry *findEntry(const UNPKinfo *info, const char *name) hi = middle - 1; } /* while */ - BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); + BAIL_MACRO(PHYSFS_ERR_NO_SUCH_PATH, NULL); } /* findEntry */ @@ -221,19 +221,19 @@ PHYSFS_Io *UNPK_openRead(dvoid *opaque, const char *fnm, int *fileExists) entry = findEntry(info, fnm); *fileExists = (entry != NULL); - GOTO_IF_MACRO(entry == NULL, NULL, UNPK_openRead_failed); + GOTO_IF_MACRO(!entry, ERRPASS, UNPK_openRead_failed); retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, UNPK_openRead_failed); + GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_openRead_failed); finfo = (UNPKfileinfo *) allocator.Malloc(sizeof (UNPKfileinfo)); - GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, UNPK_openRead_failed); + GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, UNPK_openRead_failed); finfo->io = info->io->duplicate(info->io); - GOTO_IF_MACRO(finfo->io == NULL, NULL, UNPK_openRead_failed); + GOTO_IF_MACRO(!finfo->io, ERRPASS, UNPK_openRead_failed); if (!finfo->io->seek(finfo->io, entry->startPos)) - GOTO_MACRO(NULL, UNPK_openRead_failed); + goto UNPK_openRead_failed; finfo->curPos = 0; finfo->entry = entry; @@ -259,30 +259,30 @@ PHYSFS_Io *UNPK_openRead(dvoid *opaque, const char *fnm, int *fileExists) PHYSFS_Io *UNPK_openWrite(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* UNPK_openWrite */ PHYSFS_Io *UNPK_openAppend(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* UNPK_openAppend */ int UNPK_remove(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* UNPK_remove */ int UNPK_mkdir(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* UNPK_mkdir */ int UNPK_stat(dvoid *opaque, const char *filename, int *exists, - PHYSFS_Stat *stat) + PHYSFS_Stat *stat) { const UNPKinfo *info = (const UNPKinfo *) opaque; const UNPKentry *entry = findEntry(info, filename); @@ -308,7 +308,7 @@ dvoid *UNPK_openArchive(PHYSFS_Io *io, UNPKentry *e, const PHYSFS_uint32 num) if (info == NULL) { allocator.Free(e); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* if */ __PHYSFS_sort(e, num, entryCmp, entrySwap); diff --git a/src/archiver_wad.c b/src/archiver_wad.c index d0660a6f..9951739c 100644 --- a/src/archiver_wad.c +++ b/src/archiver_wad.c @@ -53,19 +53,19 @@ static UNPKentry *wadLoadEntries(PHYSFS_Io *io, PHYSFS_uint32 fileCount) UNPKentry *entries = NULL; UNPKentry *entry = NULL; - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &directoryOffset, 4), NULL, 0); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &directoryOffset, 4), ERRPASS, 0); directoryOffset = PHYSFS_swapULE32(directoryOffset); - BAIL_IF_MACRO(!io->seek(io, directoryOffset), NULL, 0); + BAIL_IF_MACRO(!io->seek(io, directoryOffset), ERRPASS, 0); entries = (UNPKentry *) allocator.Malloc(sizeof (UNPKentry) * fileCount); - BAIL_IF_MACRO(entries == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!entries, PHYSFS_ERR_OUT_OF_MEMORY, NULL); for (entry = entries; fileCount > 0; fileCount--, entry++) { - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->startPos, 4), NULL, failed); - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->size, 4), NULL, failed); - GOTO_IF_MACRO(!__PHYSFS_readAll(io, &entry->name, 8), NULL, failed); + if (!__PHYSFS_readAll(io, &entry->startPos, 4)) goto failed; + if (!__PHYSFS_readAll(io, &entry->size, 4)) goto failed; + if (!__PHYSFS_readAll(io, &entry->name, 8)) goto failed; entry->name[8] = '\0'; /* name might not be null-terminated in file. */ entry->size = PHYSFS_swapULE32(entry->size); @@ -88,16 +88,16 @@ static void *WAD_openArchive(PHYSFS_Io *io, const char *name, int forWriting) assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, 0); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, sizeof (buf)), NULL, NULL); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, buf, sizeof (buf)), ERRPASS, NULL); if ((memcmp(buf, "IWAD", 4) != 0) && (memcmp(buf, "PWAD", 4) != 0)) - BAIL_MACRO(ERR_NOT_AN_ARCHIVE, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof (count)), NULL, NULL); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &count, sizeof (count)), ERRPASS, NULL); count = PHYSFS_swapULE32(count); entries = wadLoadEntries(io, count); - BAIL_IF_MACRO(entries == NULL, NULL, NULL); + BAIL_IF_MACRO(!entries, ERRPASS, NULL); return UNPK_openArchive(io, entries, count); } /* WAD_openArchive */ diff --git a/src/archiver_zip.c b/src/archiver_zip.c index 98f65f95..88f88785 100644 --- a/src/archiver_zip.c +++ b/src/archiver_zip.c @@ -141,19 +141,15 @@ static void initializeZStream(z_stream *pstr) } /* initializeZStream */ -static const char *zlib_error_string(int rc) +static PHYSFS_ErrorCode zlib_error_code(int rc) { switch (rc) { - case Z_OK: return NULL; /* not an error. */ - case Z_STREAM_END: return NULL; /* not an error. */ - case Z_ERRNO: return ERR_IO_ERROR; - case Z_NEED_DICT: return ERR_NEED_DICT; - case Z_DATA_ERROR: return ERR_DATA_ERROR; - case Z_MEM_ERROR: return ERR_MEMORY_ERROR; - case Z_BUF_ERROR: return ERR_BUFFER_ERROR; - case Z_VERSION_ERROR: return ERR_VERSION_ERROR; - default: return ERR_UNKNOWN_ERROR; + case Z_OK: return PHYSFS_ERR_OK; /* not an error. */ + case Z_STREAM_END: return PHYSFS_ERR_OK; /* not an error. */ + case Z_ERRNO: return PHYSFS_ERR_IO; + case Z_MEM_ERROR: return PHYSFS_ERR_OUT_OF_MEMORY; + default: return PHYSFS_ERR_CORRUPT; } /* switch */ } /* zlib_error_string */ @@ -161,11 +157,9 @@ static const char *zlib_error_string(int rc) /* * Wrap all zlib calls in this, so the physfs error state is set appropriately. */ -static int zlib_err(int rc) +static int zlib_err(const int rc) { - const char *str = zlib_error_string(rc); - if (str != NULL) - __PHYSFS_setError(str); + __PHYSFS_setError(zlib_error_code(rc)); return rc; } /* zlib_err */ @@ -176,7 +170,7 @@ static int zlib_err(int rc) static int readui32(PHYSFS_Io *io, PHYSFS_uint32 *val) { PHYSFS_uint32 v; - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &v, sizeof (v)), NULL, 0); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &v, sizeof (v)), ERRPASS, 0); *val = PHYSFS_swapULE32(v); return 1; } /* readui32 */ @@ -188,7 +182,7 @@ static int readui32(PHYSFS_Io *io, PHYSFS_uint32 *val) static int readui16(PHYSFS_Io *io, PHYSFS_uint16 *val) { PHYSFS_uint16 v; - BAIL_IF_MACRO(!__PHYSFS_readAll(io, &v, sizeof (v)), NULL, 0); + BAIL_IF_MACRO(!__PHYSFS_readAll(io, &v, sizeof (v)), ERRPASS, 0); *val = PHYSFS_swapULE16(v); return 1; } /* readui16 */ @@ -207,7 +201,7 @@ static PHYSFS_sint64 ZIP_read(PHYSFS_Io *_io, void *buf, PHYSFS_uint64 len) if (avail < maxread) maxread = avail; - BAIL_IF_MACRO(maxread == 0, NULL, 0); /* quick rejection. */ + BAIL_IF_MACRO(maxread == 0, ERRPASS, 0); /* quick rejection. */ if (entry->compression_method == COMPMETH_NONE) retval = io->read(io, buf, maxread); @@ -256,9 +250,11 @@ static PHYSFS_sint64 ZIP_read(PHYSFS_Io *_io, void *buf, PHYSFS_uint64 len) } /* ZIP_read */ +/* !!! FIXME: write stuff should be ERR_READ_ONLY, not ERR_UNSUPPORTED */ +/* !!! FIXME: ... all the archivers do this. */ static PHYSFS_sint64 ZIP_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 len) { - BAIL_MACRO(ERR_NOT_SUPPORTED, -1); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, -1); } /* ZIP_write */ @@ -274,12 +270,12 @@ static int ZIP_seek(PHYSFS_Io *_io, PHYSFS_uint64 offset) ZIPentry *entry = finfo->entry; PHYSFS_Io *io = finfo->io; - BAIL_IF_MACRO(offset > entry->uncompressed_size, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(offset > entry->uncompressed_size, PHYSFS_ERR_PAST_EOF, 0); if (entry->compression_method == COMPMETH_NONE) { const PHYSFS_sint64 newpos = offset + entry->offset; - BAIL_IF_MACRO(!io->seek(io, newpos), NULL, 0); + BAIL_IF_MACRO(!io->seek(io, newpos), ERRPASS, 0); finfo->uncompressed_position = (PHYSFS_uint32) offset; } /* if */ @@ -339,19 +335,20 @@ static PHYSFS_Io *ZIP_duplicate(PHYSFS_Io *io) ZIPfileinfo *origfinfo = (ZIPfileinfo *) io->opaque; PHYSFS_Io *retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); ZIPfileinfo *finfo = (ZIPfileinfo *) allocator.Malloc(sizeof (ZIPfileinfo)); - GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, ZIP_duplicate_failed); - GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, ZIP_duplicate_failed); + GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_duplicate_failed); + GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_duplicate_failed); memset(finfo, '\0', sizeof (*finfo)); finfo->entry = origfinfo->entry; finfo->io = zip_get_io(origfinfo->io, NULL, finfo->entry); - GOTO_IF_MACRO(finfo->io == NULL, NULL, ZIP_duplicate_failed); + GOTO_IF_MACRO(!finfo->io, ERRPASS, ZIP_duplicate_failed); if (finfo->entry->compression_method != COMPMETH_NONE) { finfo->buffer = (PHYSFS_uint8 *) allocator.Malloc(ZIP_READBUFSIZE); - GOTO_IF_MACRO(!finfo->buffer, ERR_OUT_OF_MEMORY, ZIP_duplicate_failed); - if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK) + if (!finfo->buffer) + GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, ZIP_duplicate_failed); + else if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK) goto ZIP_duplicate_failed; } /* if */ @@ -425,7 +422,7 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(PHYSFS_Io *io, PHYSFS_sint64 *l int found = 0; filelen = io->length(io); - BAIL_IF_MACRO(filelen == -1, NULL, 0); + BAIL_IF_MACRO(filelen == -1, ERRPASS, 0); /* * Jump to the end of the file and start reading backwards. @@ -452,7 +449,7 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(PHYSFS_Io *io, PHYSFS_sint64 *l while ((totalread < filelen) && (totalread < 65557)) { - BAIL_IF_MACRO(!io->seek(io, filepos), NULL, -1); + BAIL_IF_MACRO(!io->seek(io, filepos), ERRPASS, -1); /* make sure we catch a signature between buffers. */ if (totalread != 0) @@ -491,7 +488,7 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(PHYSFS_Io *io, PHYSFS_sint64 *l filepos = 0; } /* while */ - BAIL_IF_MACRO(!found, ERR_NOT_AN_ARCHIVE, -1); + BAIL_IF_MACRO(!found, PHYSFS_ERR_UNSUPPORTED, -1); if (len != NULL) *len = filelen; @@ -591,7 +588,7 @@ static ZIPentry *zip_find_entry(const ZIPinfo *info, const char *path, if (isDir != NULL) *isDir = 0; - BAIL_MACRO(ERR_NO_SUCH_FILE, NULL); + BAIL_MACRO(PHYSFS_ERR_NO_SUCH_PATH, NULL); } /* zip_find_entry */ @@ -713,10 +710,10 @@ static int zip_resolve_symlink(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry) * follow it. */ - BAIL_IF_MACRO(!io->seek(io, entry->offset), NULL, 0); + BAIL_IF_MACRO(!io->seek(io, entry->offset), ERRPASS, 0); path = (char *) allocator.Malloc(size + 1); - BAIL_IF_MACRO(path == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(path == NULL, PHYSFS_ERR_OUT_OF_MEMORY, 0); if (entry->compression_method == COMPMETH_NONE) rc = __PHYSFS_readAll(io, path, size); @@ -778,23 +775,23 @@ static int zip_parse_local(PHYSFS_Io *io, ZIPentry *entry) * aren't zero. That seems to work well. */ - BAIL_IF_MACRO(!io->seek(io, entry->offset), NULL, 0); - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); - BAIL_IF_MACRO(ui32 != ZIP_LOCAL_FILE_SIG, ERR_CORRUPTED, 0); - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); - BAIL_IF_MACRO(ui16 != entry->version_needed, ERR_CORRUPTED, 0); - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); /* general bits. */ - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); - BAIL_IF_MACRO(ui16 != entry->compression_method, ERR_CORRUPTED, 0); - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); /* date/time */ - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); - BAIL_IF_MACRO(ui32 && (ui32 != entry->crc), ERR_CORRUPTED, 0); - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); - BAIL_IF_MACRO(ui32 && (ui32 != entry->compressed_size), ERR_CORRUPTED, 0); - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); - BAIL_IF_MACRO(ui32 && (ui32 != entry->uncompressed_size),ERR_CORRUPTED,0); - BAIL_IF_MACRO(!readui16(io, &fnamelen), NULL, 0); - BAIL_IF_MACRO(!readui16(io, &extralen), NULL, 0); + BAIL_IF_MACRO(!io->seek(io, entry->offset), ERRPASS, 0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); + BAIL_IF_MACRO(ui32 != ZIP_LOCAL_FILE_SIG, PHYSFS_ERR_CORRUPT, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); + BAIL_IF_MACRO(ui16 != entry->version_needed, PHYSFS_ERR_CORRUPT, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); /* general bits. */ + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); + BAIL_IF_MACRO(ui16 != entry->compression_method, PHYSFS_ERR_CORRUPT, 0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); /* date/time */ + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); + BAIL_IF_MACRO(ui32 && (ui32 != entry->crc), PHYSFS_ERR_CORRUPT, 0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); + BAIL_IF_MACRO(ui32 && (ui32!=entry->compressed_size),PHYSFS_ERR_CORRUPT,0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); + BAIL_IF_MACRO(ui32&&(ui32!=entry->uncompressed_size),PHYSFS_ERR_CORRUPT,0); + BAIL_IF_MACRO(!readui16(io, &fnamelen), ERRPASS, 0); + BAIL_IF_MACRO(!readui16(io, &extralen), ERRPASS, 0); entry->offset += fnamelen + extralen + 30; return 1; @@ -807,11 +804,11 @@ static int zip_resolve(PHYSFS_Io *io, ZIPinfo *info, ZIPentry *entry) ZipResolveType resolve_type = entry->resolved; /* Don't bother if we've failed to resolve this entry before. */ - BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_FILE, ERR_CORRUPTED, 0); - BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_SYMLINK, ERR_CORRUPTED, 0); + BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_FILE, PHYSFS_ERR_CORRUPT, 0); + BAIL_IF_MACRO(resolve_type == ZIP_BROKEN_SYMLINK, PHYSFS_ERR_CORRUPT, 0); /* uhoh...infinite symlink loop! */ - BAIL_IF_MACRO(resolve_type == ZIP_RESOLVING, ERR_SYMLINK_LOOP, 0); + BAIL_IF_MACRO(resolve_type == ZIP_RESOLVING, PHYSFS_ERR_SYMLINK_LOOP, 0); /* * We fix up the offset to point to the actual data on the @@ -930,26 +927,26 @@ static int zip_load_entry(PHYSFS_Io *io, ZIPentry *entry, PHYSFS_uint32 ofs_fixu PHYSFS_sint64 si64; /* sanity check with central directory signature... */ - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); - BAIL_IF_MACRO(ui32 != ZIP_CENTRAL_DIR_SIG, ERR_CORRUPTED, 0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); + BAIL_IF_MACRO(ui32 != ZIP_CENTRAL_DIR_SIG, PHYSFS_ERR_CORRUPT, 0); /* Get the pertinent parts of the record... */ - BAIL_IF_MACRO(!readui16(io, &entry->version), NULL, 0); - BAIL_IF_MACRO(!readui16(io, &entry->version_needed), NULL, 0); - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); /* general bits */ - BAIL_IF_MACRO(!readui16(io, &entry->compression_method), NULL, 0); - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); + BAIL_IF_MACRO(!readui16(io, &entry->version), ERRPASS, 0); + BAIL_IF_MACRO(!readui16(io, &entry->version_needed), ERRPASS, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); /* general bits */ + BAIL_IF_MACRO(!readui16(io, &entry->compression_method), ERRPASS, 0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); entry->last_mod_time = zip_dos_time_to_physfs_time(ui32); - BAIL_IF_MACRO(!readui32(io, &entry->crc), NULL, 0); - BAIL_IF_MACRO(!readui32(io, &entry->compressed_size), NULL, 0); - BAIL_IF_MACRO(!readui32(io, &entry->uncompressed_size), NULL, 0); - BAIL_IF_MACRO(!readui16(io, &fnamelen), NULL, 0); - BAIL_IF_MACRO(!readui16(io, &extralen), NULL, 0); - BAIL_IF_MACRO(!readui16(io, &commentlen), NULL, 0); - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); /* disk number start */ - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); /* internal file attribs */ - BAIL_IF_MACRO(!readui32(io, &external_attr), NULL, 0); - BAIL_IF_MACRO(!readui32(io, &entry->offset), NULL, 0); + BAIL_IF_MACRO(!readui32(io, &entry->crc), ERRPASS, 0); + BAIL_IF_MACRO(!readui32(io, &entry->compressed_size), ERRPASS, 0); + BAIL_IF_MACRO(!readui32(io, &entry->uncompressed_size), ERRPASS, 0); + BAIL_IF_MACRO(!readui16(io, &fnamelen), ERRPASS, 0); + BAIL_IF_MACRO(!readui16(io, &extralen), ERRPASS, 0); + BAIL_IF_MACRO(!readui16(io, &commentlen), ERRPASS, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); /* disk number start */ + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); /* internal file attribs */ + BAIL_IF_MACRO(!readui32(io, &external_attr), ERRPASS, 0); + BAIL_IF_MACRO(!readui32(io, &entry->offset), ERRPASS, 0); entry->offset += ofs_fixup; entry->symlink = NULL; /* will be resolved later, if necessary. */ @@ -957,7 +954,7 @@ static int zip_load_entry(PHYSFS_Io *io, ZIPentry *entry, PHYSFS_uint32 ofs_fixu ZIP_UNRESOLVED_SYMLINK : ZIP_UNRESOLVED_FILE; entry->name = (char *) allocator.Malloc(fnamelen + 1); - BAIL_IF_MACRO(entry->name == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(entry->name == NULL, PHYSFS_ERR_OUT_OF_MEMORY, 0); if (!__PHYSFS_readAll(io, entry->name, fnamelen)) goto zip_load_entry_puked; @@ -1012,10 +1009,10 @@ static int zip_load_entries(PHYSFS_Io *io, ZIPinfo *info, PHYSFS_uint32 max = info->entryCount; PHYSFS_uint32 i; - BAIL_IF_MACRO(!io->seek(io, central_ofs), NULL, 0); + BAIL_IF_MACRO(!io->seek(io, central_ofs), ERRPASS, 0); info->entries = (ZIPentry *) allocator.Malloc(sizeof (ZIPentry) * max); - BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!info->entries, PHYSFS_ERR_OUT_OF_MEMORY, 0); for (i = 0; i < max; i++) { @@ -1040,36 +1037,38 @@ static int zip_parse_end_of_central_dir(PHYSFS_Io *io, ZIPinfo *info, PHYSFS_sint64 len; PHYSFS_sint64 pos; + /* !!! FIXME: ERR_UNSUPPORTED should be ERR_CORRUPT...right? */ + /* find the end-of-central-dir record, and seek to it. */ pos = zip_find_end_of_central_dir(io, &len); - BAIL_IF_MACRO(pos == -1, NULL, 0); - BAIL_IF_MACRO(!io->seek(io, pos), NULL, 0); + BAIL_IF_MACRO(pos == -1, ERRPASS, 0); + BAIL_IF_MACRO(!io->seek(io, pos), ERRPASS, 0); /* check signature again, just in case. */ - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); - BAIL_IF_MACRO(ui32 != ZIP_END_OF_CENTRAL_DIR_SIG, ERR_NOT_AN_ARCHIVE, 0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); + BAIL_IF_MACRO(ui32 != ZIP_END_OF_CENTRAL_DIR_SIG, PHYSFS_ERR_UNSUPPORTED, 0); /* number of this disk */ - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); - BAIL_IF_MACRO(ui16 != 0, ERR_UNSUPPORTED_ARCHIVE, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); + BAIL_IF_MACRO(ui16 != 0, PHYSFS_ERR_UNSUPPORTED, 0); /* number of the disk with the start of the central directory */ - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); - BAIL_IF_MACRO(ui16 != 0, ERR_UNSUPPORTED_ARCHIVE, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); + BAIL_IF_MACRO(ui16 != 0, PHYSFS_ERR_UNSUPPORTED, 0); /* total number of entries in the central dir on this disk */ - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); /* total number of entries in the central dir */ - BAIL_IF_MACRO(!readui16(io, &info->entryCount), NULL, 0); - BAIL_IF_MACRO(ui16 != info->entryCount, ERR_UNSUPPORTED_ARCHIVE, 0); + BAIL_IF_MACRO(!readui16(io, &info->entryCount), ERRPASS, 0); + BAIL_IF_MACRO(ui16 != info->entryCount, PHYSFS_ERR_UNSUPPORTED, 0); /* size of the central directory */ - BAIL_IF_MACRO(!readui32(io, &ui32), NULL, 0); + BAIL_IF_MACRO(!readui32(io, &ui32), ERRPASS, 0); /* offset of central directory */ - BAIL_IF_MACRO(!readui32(io, central_dir_ofs), NULL, 0); - BAIL_IF_MACRO(pos < *central_dir_ofs + ui32, ERR_UNSUPPORTED_ARCHIVE, 0); + BAIL_IF_MACRO(!readui32(io, central_dir_ofs), ERRPASS, 0); + BAIL_IF_MACRO(pos < *central_dir_ofs + ui32, PHYSFS_ERR_UNSUPPORTED, 0); /* * For self-extracting archives, etc, there's crapola in the file @@ -1085,14 +1084,14 @@ static int zip_parse_end_of_central_dir(PHYSFS_Io *io, ZIPinfo *info, *central_dir_ofs += *data_start; /* zipfile comment length */ - BAIL_IF_MACRO(!readui16(io, &ui16), NULL, 0); + BAIL_IF_MACRO(!readui16(io, &ui16), ERRPASS, 0); /* * Make sure that the comment length matches to the end of file... * If it doesn't, we're either in the wrong part of the file, or the * file is corrupted, but we give up either way. */ - BAIL_IF_MACRO((pos + 22 + ui16) != len, ERR_UNSUPPORTED_ARCHIVE, 0); + BAIL_IF_MACRO((pos + 22 + ui16) != len, PHYSFS_ERR_UNSUPPORTED, 0); return 1; /* made it. */ } /* zip_parse_end_of_central_dir */ @@ -1106,11 +1105,11 @@ static void *ZIP_openArchive(PHYSFS_Io *io, const char *name, int forWriting) assert(io != NULL); /* shouldn't ever happen. */ - BAIL_IF_MACRO(forWriting, ERR_ARC_IS_READ_ONLY, NULL); - BAIL_IF_MACRO(!isZip(io), NULL, NULL); + BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL); + BAIL_IF_MACRO(!isZip(io), ERRPASS, NULL); info = (ZIPinfo *) allocator.Malloc(sizeof (ZIPinfo)); - BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!info, PHYSFS_ERR_OUT_OF_MEMORY, NULL); memset(info, '\0', sizeof (ZIPinfo)); info->io = io; @@ -1250,7 +1249,9 @@ static PHYSFS_Io *zip_get_io(PHYSFS_Io *io, ZIPinfo *inf, ZIPentry *entry) { int success; PHYSFS_Io *retval = io->duplicate(io); - BAIL_IF_MACRO(retval == NULL, NULL, NULL); + BAIL_IF_MACRO(!retval, ERRPASS, NULL); + + /* !!! FIXME: if you open a dir here, it should bail ERR_NOT_A_FILE */ /* (inf) can be NULL if we already resolved. */ success = (inf == NULL) || zip_resolve(retval, inf, entry); @@ -1279,25 +1280,26 @@ static PHYSFS_Io *ZIP_openRead(dvoid *opaque, const char *fnm, int *fileExists) ZIPfileinfo *finfo = NULL; *fileExists = (entry != NULL); - BAIL_IF_MACRO(entry == NULL, NULL, NULL); + BAIL_IF_MACRO(!entry, ERRPASS, NULL); retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, ZIP_openRead_failed); + GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_openRead_failed); finfo = (ZIPfileinfo *) allocator.Malloc(sizeof (ZIPfileinfo)); - GOTO_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, ZIP_openRead_failed); + GOTO_IF_MACRO(!finfo, PHYSFS_ERR_OUT_OF_MEMORY, ZIP_openRead_failed); memset(finfo, '\0', sizeof (ZIPfileinfo)); finfo->io = zip_get_io(info->io, info, entry); - GOTO_IF_MACRO(finfo->io == NULL, NULL, ZIP_openRead_failed); + GOTO_IF_MACRO(!finfo->io, ERRPASS, ZIP_openRead_failed); finfo->entry = ((entry->symlink != NULL) ? entry->symlink : entry); initializeZStream(&finfo->stream); if (finfo->entry->compression_method != COMPMETH_NONE) { finfo->buffer = (PHYSFS_uint8 *) allocator.Malloc(ZIP_READBUFSIZE); - GOTO_IF_MACRO(!finfo->buffer, ERR_OUT_OF_MEMORY, ZIP_openRead_failed); - if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK) + if (!finfo->buffer) + GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, ZIP_openRead_failed); + else if (zlib_err(inflateInit2(&finfo->stream, -MAX_WBITS)) != Z_OK) goto ZIP_openRead_failed; } /* if */ @@ -1330,13 +1332,13 @@ static PHYSFS_Io *ZIP_openRead(dvoid *opaque, const char *fnm, int *fileExists) static PHYSFS_Io *ZIP_openWrite(dvoid *opaque, const char *filename) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* ZIP_openWrite */ static PHYSFS_Io *ZIP_openAppend(dvoid *opaque, const char *filename) { - BAIL_MACRO(ERR_NOT_SUPPORTED, NULL); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL); } /* ZIP_openAppend */ @@ -1351,13 +1353,13 @@ static void ZIP_dirClose(dvoid *opaque) static int ZIP_remove(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* ZIP_remove */ static int ZIP_mkdir(dvoid *opaque, const char *name) { - BAIL_MACRO(ERR_NOT_SUPPORTED, 0); + BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, 0); } /* ZIP_mkdir */ diff --git a/src/physfs.c b/src/physfs.c index 3d6293bd..4a1cd3a8 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -38,13 +38,12 @@ typedef struct __PHYSFS_FILEHANDLE__ } FileHandle; -typedef struct __PHYSFS_ERRMSGTYPE__ +typedef struct __PHYSFS_ERRSTATETYPE__ { void *tid; - int errorAvailable; - char errorString[80]; - struct __PHYSFS_ERRMSGTYPE__ *next; -} ErrMsg; + PHYSFS_ErrorCode code; + struct __PHYSFS_ERRSTATETYPE__ *next; +} ErrState; /* The various i/o drivers...some of these may not be compiled in. */ @@ -129,7 +128,7 @@ static const PHYSFS_Archiver *archivers[] = /* General PhysicsFS state ... */ static int initialized = 0; -static ErrMsg *errorMessages = NULL; +static ErrState *errorStates = NULL; static DirHandle *searchPath = NULL; static DirHandle *writeDir = NULL; static FileHandle *openWriteList = NULL; @@ -231,11 +230,11 @@ PHYSFS_Io *__PHYSFS_createNativeIo(const char *path, const int mode) assert((mode == 'r') || (mode == 'w') || (mode == 'a')); io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - GOTO_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, createNativeIo_failed); + GOTO_IF_MACRO(!io, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed); info = (NativeIoInfo *) allocator.Malloc(sizeof (NativeIoInfo)); - GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, createNativeIo_failed); + GOTO_IF_MACRO(!info, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed); pathdup = (char *) allocator.Malloc(strlen(path) + 1); - GOTO_IF_MACRO(pathdup == NULL, ERR_OUT_OF_MEMORY, createNativeIo_failed); + GOTO_IF_MACRO(!pathdup, PHYSFS_ERR_OUT_OF_MEMORY, createNativeIo_failed); if (mode == 'r') handle = __PHYSFS_platformOpenRead(path); @@ -244,7 +243,7 @@ PHYSFS_Io *__PHYSFS_createNativeIo(const char *path, const int mode) else if (mode == 'a') handle = __PHYSFS_platformOpenAppend(path); - GOTO_IF_MACRO(handle == NULL, NULL, createNativeIo_failed); + GOTO_IF_MACRO(!handle, ERRPASS, createNativeIo_failed); strcpy(pathdup, path); info->handle = handle; @@ -295,13 +294,13 @@ static PHYSFS_sint64 memoryIo_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len) static PHYSFS_sint64 memoryIo_write(PHYSFS_Io *io, const void *buffer, PHYSFS_uint64 len) { - BAIL_MACRO(ERR_NOT_SUPPORTED, -1); + BAIL_MACRO(PHYSFS_ERR_OPEN_FOR_READING, -1); } /* memoryIo_write */ static int memoryIo_seek(PHYSFS_Io *io, PHYSFS_uint64 offset) { MemoryIoInfo *info = (MemoryIoInfo *) io->opaque; - BAIL_IF_MACRO(offset > info->len, ERR_PAST_EOF, 0); + BAIL_IF_MACRO(offset > info->len, PHYSFS_ERR_PAST_EOF, 0); info->pos = offset; return 1; } /* memoryIo_seek */ @@ -335,12 +334,12 @@ static PHYSFS_Io *memoryIo_duplicate(PHYSFS_Io *io) /* we're the parent. */ retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); newinfo = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo)); if (!newinfo) { allocator.Free(retval); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* if */ /* !!! FIXME: want lockless atomic increment. */ @@ -423,9 +422,9 @@ PHYSFS_Io *__PHYSFS_createMemoryIo(const void *buf, PHYSFS_uint64 len, MemoryIoInfo *info = NULL; io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - GOTO_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, createMemoryIo_failed); + GOTO_IF_MACRO(!io, PHYSFS_ERR_OUT_OF_MEMORY, createMemoryIo_failed); info = (MemoryIoInfo *) allocator.Malloc(sizeof (MemoryIoInfo)); - GOTO_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, createMemoryIo_failed); + GOTO_IF_MACRO(!info, PHYSFS_ERR_OUT_OF_MEMORY, createMemoryIo_failed); memset(info, '\0', sizeof (*info)); info->buf = (const PHYSFS_uint8 *) buf; @@ -484,23 +483,24 @@ static PHYSFS_Io *handleIo_duplicate(PHYSFS_Io *io) FileHandle *newfh = (FileHandle *) allocator.Malloc(sizeof (FileHandle)); PHYSFS_Io *retval = NULL; - GOTO_IF_MACRO(newfh == NULL, ERR_OUT_OF_MEMORY, handleIo_dupe_failed); + GOTO_IF_MACRO(!newfh, PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed); memset(newfh, '\0', sizeof (*newfh)); retval = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - GOTO_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, handleIo_dupe_failed); + GOTO_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed); #if 0 /* we don't buffer the duplicate, at least not at the moment. */ if (origfh->buffer != NULL) { newfh->buffer = (PHYSFS_uint8 *) allocator.Malloc(origfh->bufsize); - GOTO_IF_MACRO(!newfh->buffer, ERR_OUT_OF_MEMORY, handleIo_dupe_failed); + if (!newfh->buffer) + GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, handleIo_dupe_failed); newfh->bufsize = origfh->bufsize; } /* if */ #endif newfh->io = origfh->io->duplicate(origfh->io); - GOTO_IF_MACRO(newfh->io == NULL, NULL, handleIo_dupe_failed); + GOTO_IF_MACRO(!newfh->io, ERRPASS, handleIo_dupe_failed); newfh->forReading = origfh->forReading; newfh->dirHandle = origfh->dirHandle; @@ -561,7 +561,7 @@ static const PHYSFS_Io __PHYSFS_handleIoInterface = static PHYSFS_Io *__PHYSFS_createHandleIo(PHYSFS_File *f) { PHYSFS_Io *io = (PHYSFS_Io *) allocator.Malloc(sizeof (PHYSFS_Io)); - BAIL_IF_MACRO(io == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!io, PHYSFS_ERR_OUT_OF_MEMORY, NULL); memcpy(io, &__PHYSFS_handleIoInterface, sizeof (*io)); io->opaque = f; return io; @@ -574,7 +574,7 @@ typedef struct { char **list; PHYSFS_uint32 size; - const char *errorstr; + PHYSFS_ErrorCode errcode; } EnumStringListCallbackData; static void enumStringListCallback(void *data, const char *str) @@ -583,7 +583,7 @@ static void enumStringListCallback(void *data, const char *str) char *newstr; EnumStringListCallbackData *pecd = (EnumStringListCallbackData *) data; - if (pecd->errorstr) + if (pecd->errcode) return; ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *)); @@ -593,7 +593,7 @@ static void enumStringListCallback(void *data, const char *str) if ((ptr == NULL) || (newstr == NULL)) { - pecd->errorstr = ERR_OUT_OF_MEMORY; + pecd->errcode = PHYSFS_ERR_OUT_OF_MEMORY; pecd->list[pecd->size] = NULL; PHYSFS_freeList(pecd->list); return; @@ -610,9 +610,15 @@ static char **doEnumStringList(void (*func)(PHYSFS_StringCallback, void *)) EnumStringListCallbackData ecd; memset(&ecd, '\0', sizeof (ecd)); ecd.list = (char **) allocator.Malloc(sizeof (char *)); - BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!ecd.list, PHYSFS_ERR_OUT_OF_MEMORY, NULL); func(enumStringListCallback, &ecd); - BAIL_IF_MACRO(ecd.errorstr != NULL, ecd.errorstr, NULL); + + if (ecd.errcode) + { + __PHYSFS_setError(ecd.errcode); + return NULL; + } /* if */ + ecd.list[ecd.size] = NULL; return ecd.list; } /* doEnumStringList */ @@ -690,19 +696,19 @@ void __PHYSFS_sort(void *entries, PHYSFS_uint32 max, } /* __PHYSFS_sort */ -static ErrMsg *findErrorForCurrentThread(void) +static ErrState *findErrorForCurrentThread(void) { - ErrMsg *i; + ErrState *i; void *tid; if (errorLock != NULL) __PHYSFS_platformGrabMutex(errorLock); - if (errorMessages != NULL) + if (errorStates != NULL) { tid = __PHYSFS_platformGetThreadID(); - for (i = errorMessages; i != NULL; i = i->next) + for (i = errorStates; i != NULL; i = i->next) { if (i->tid == tid) { @@ -720,66 +726,111 @@ static ErrMsg *findErrorForCurrentThread(void) } /* findErrorForCurrentThread */ -void __PHYSFS_setError(const char *str) +void __PHYSFS_setError(const PHYSFS_ErrorCode errcode) { - ErrMsg *err; + ErrState *err; - if (str == NULL) + if (!errcode) return; err = findErrorForCurrentThread(); - if (err == NULL) { - err = (ErrMsg *) allocator.Malloc(sizeof (ErrMsg)); + err = (ErrState *) allocator.Malloc(sizeof (ErrState)); if (err == NULL) return; /* uhh...? */ - memset((void *) err, '\0', sizeof (ErrMsg)); + memset(err, '\0', sizeof (ErrState)); err->tid = __PHYSFS_platformGetThreadID(); if (errorLock != NULL) __PHYSFS_platformGrabMutex(errorLock); - err->next = errorMessages; - errorMessages = err; + err->next = errorStates; + errorStates = err; if (errorLock != NULL) __PHYSFS_platformReleaseMutex(errorLock); } /* if */ - err->errorAvailable = 1; - strncpy(err->errorString, str, sizeof (err->errorString)); - err->errorString[sizeof (err->errorString) - 1] = '\0'; + err->code = errcode; } /* __PHYSFS_setError */ -const char *PHYSFS_getLastError(void) +PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void) { - ErrMsg *err = findErrorForCurrentThread(); + ErrState *err = findErrorForCurrentThread(); + const PHYSFS_ErrorCode retval = (err) ? err->code : PHYSFS_ERR_OK; + if (err) + err->code = PHYSFS_ERR_OK; + return retval; +} /* PHYSFS_getLastErrorCode */ + + +PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code) +{ + switch (code) + { + case PHYSFS_ERR_OK: return "no error"; + case PHYSFS_ERR_OTHER_ERROR: return "unknown error"; + case PHYSFS_ERR_OUT_OF_MEMORY: return "out of memory"; + case PHYSFS_ERR_NOT_INITIALIZED: return "not initialized"; + case PHYSFS_ERR_IS_INITIALIZED: return "already initialized"; + case PHYSFS_ERR_ARGV0_IS_NULL: return "argv[0] is NULL"; + case PHYSFS_ERR_UNSUPPORTED: return "unsupported"; + case PHYSFS_ERR_PAST_EOF: return "past end of file"; + case PHYSFS_ERR_FILES_STILL_OPEN: return "files still open"; + case PHYSFS_ERR_INVALID_ARGUMENT: return "invalid argument"; + case PHYSFS_ERR_NOT_MOUNTED: return "not mounted"; + case PHYSFS_ERR_NO_SUCH_PATH: return "no such path"; + case PHYSFS_ERR_SYMLINK_FORBIDDEN: return "symlinks are forbidden"; + case PHYSFS_ERR_NO_WRITE_DIR: return "write directory is not set"; + case PHYSFS_ERR_OPEN_FOR_READING: return "file open for reading"; + case PHYSFS_ERR_OPEN_FOR_WRITING: return "file open for writing"; + case PHYSFS_ERR_NOT_A_FILE: return "not a file"; + case PHYSFS_ERR_READ_ONLY: return "read-only filesystem"; + case PHYSFS_ERR_CORRUPT: return "corrupted"; + case PHYSFS_ERR_SYMLINK_LOOP: return "infinite symbolic link loop"; + case PHYSFS_ERR_IO: return "i/o error"; + case PHYSFS_ERR_PERMISSION: return "permission denied"; + case PHYSFS_ERR_NO_SPACE: return "no space available for writing"; + case PHYSFS_ERR_BAD_FILENAME: return "filename is illegal or insecure"; + case PHYSFS_ERR_BUSY: return "tried to modify a file the OS needs"; + case PHYSFS_ERR_DIR_NOT_EMPTY: return "directory isn't empty"; + case PHYSFS_ERR_OS_ERROR: return "OS reported an error"; + } /* switch */ + + return NULL; /* don't know this error code. */ +} /* PHYSFS_getErrorByCode */ + + +void PHYSFS_setErrorCode(PHYSFS_ErrorCode code) +{ + __PHYSFS_setError(code); +} /* PHYSFS_setErrorCode */ - if ((err == NULL) || (!err->errorAvailable)) - return NULL; - err->errorAvailable = 0; - return err->errorString; +const char *PHYSFS_getLastError(void) +{ + const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode(); + return (err) ? PHYSFS_getErrorByCode(err) : NULL; } /* PHYSFS_getLastError */ /* MAKE SURE that errorLock is held before calling this! */ -static void freeErrorMessages(void) +static void freeErrorStates(void) { - ErrMsg *i; - ErrMsg *next; + ErrState *i; + ErrState *next; - for (i = errorMessages; i != NULL; i = next) + for (i = errorStates; i != NULL; i = next) { next = i->next; allocator.Free(i); } /* for */ - errorMessages = NULL; -} /* freeErrorMessages */ + errorStates = NULL; +} /* freeErrorStates */ void PHYSFS_getLinkedVersion(PHYSFS_Version *ver) @@ -823,7 +874,7 @@ static DirHandle *tryOpenDir(PHYSFS_Io *io, const PHYSFS_Archiver *funcs, void *opaque = NULL; if (io != NULL) - BAIL_IF_MACRO(!io->seek(io, 0), NULL, NULL); + BAIL_IF_MACRO(!io->seek(io, 0), ERRPASS, NULL); opaque = funcs->openArchive(io, d, forWriting); if (opaque != NULL) @@ -887,7 +938,7 @@ static DirHandle *openDirectory(PHYSFS_Io *io, const char *d, int forWriting) retval = tryOpenDir(io, *i, d, forWriting); } /* else */ - BAIL_IF_MACRO(retval == NULL, ERR_UNSUPPORTED_ARCHIVE, NULL); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_UNSUPPORTED, NULL); return retval; } /* openDirectory */ @@ -914,13 +965,13 @@ static int sanitizePlatformIndependentPath(const char *src, char *dst) ch = *(src++); if ((ch == ':') || (ch == '\\')) /* illegal chars in a physfs path. */ - BAIL_MACRO(ERR_INSECURE_FNAME, 0); + BAIL_MACRO(PHYSFS_ERR_BAD_FILENAME, 0); if (ch == '/') /* path separator. */ { *dst = '\0'; /* "." and ".." are illegal pathnames. */ if ((strcmp(prev, ".") == 0) || (strcmp(prev, "..") == 0)) - BAIL_MACRO(ERR_INSECURE_FNAME, 0); + BAIL_MACRO(PHYSFS_ERR_BAD_FILENAME, 0); while (*src == '/') /* chop out doubles... */ src++; @@ -986,28 +1037,30 @@ static DirHandle *createDirHandle(PHYSFS_Io *io, const char *newDir, { const size_t len = strlen(mountPoint) + 1; tmpmntpnt = (char *) __PHYSFS_smallAlloc(len); - GOTO_IF_MACRO(!tmpmntpnt, ERR_OUT_OF_MEMORY, badDirHandle); + GOTO_IF_MACRO(!tmpmntpnt, PHYSFS_ERR_OUT_OF_MEMORY, badDirHandle); if (!sanitizePlatformIndependentPath(mountPoint, tmpmntpnt)) goto badDirHandle; mountPoint = tmpmntpnt; /* sanitized version. */ } /* if */ dirHandle = openDirectory(io, newDir, forWriting); - GOTO_IF_MACRO(!dirHandle, NULL, badDirHandle); + GOTO_IF_MACRO(!dirHandle, ERRPASS, badDirHandle); if (newDir == NULL) dirHandle->dirName = NULL; else { dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1); - GOTO_IF_MACRO(!dirHandle->dirName, ERR_OUT_OF_MEMORY, badDirHandle); + if (!dirHandle->dirName) + GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, badDirHandle); strcpy(dirHandle->dirName, newDir); } /* else */ if ((mountPoint != NULL) && (*mountPoint != '\0')) { dirHandle->mountPoint = (char *)allocator.Malloc(strlen(mountPoint)+2); - GOTO_IF_MACRO(!dirHandle->mountPoint, ERR_OUT_OF_MEMORY, badDirHandle); + if (!dirHandle->mountPoint) + GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, badDirHandle); strcpy(dirHandle->mountPoint, mountPoint); strcat(dirHandle->mountPoint, "/"); } /* if */ @@ -1038,7 +1091,7 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList) return 1; for (i = openList; i != NULL; i = i->next) - BAIL_IF_MACRO(i->dirHandle == dh, ERR_FILES_STILL_OPEN, 0); + BAIL_IF_MACRO(i->dirHandle == dh, PHYSFS_ERR_FILES_STILL_OPEN, 0); dh->funcs->dirClose(dh->opaque); allocator.Free(dh->dirName); @@ -1060,7 +1113,7 @@ static char *calculateUserDir(void) retval = (char *) allocator.Malloc(len); if (retval == NULL) - __PHYSFS_setError(ERR_OUT_OF_MEMORY); + __PHYSFS_setError(PHYSFS_ERR_OUT_OF_MEMORY); else sprintf(retval, "%susers%c%s", baseDir, dirsep, str); @@ -1110,21 +1163,21 @@ static char *calculateBaseDir(const char *argv0) return retval; /* We need argv0 to go on. */ - BAIL_IF_MACRO(argv0 == NULL, ERR_ARGV0_IS_NULL, NULL); + BAIL_IF_MACRO(argv0 == NULL, PHYSFS_ERR_ARGV0_IS_NULL, NULL); ptr = strrchr(argv0, dirsep); if (ptr != NULL) { const size_t size = (size_t) (ptr - argv0); retval = (char *) allocator.Malloc(size + 1); - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); memcpy(retval, argv0, size); retval[size] = '\0'; return retval; } /* if */ /* argv0 wasn't helpful. */ - BAIL_MACRO(ERR_INVALID_ARGUMENT, NULL); + BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, NULL); } /* calculateBaseDir */ @@ -1156,25 +1209,25 @@ static void setDefaultAllocator(void); int PHYSFS_init(const char *argv0) { - BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0); + BAIL_IF_MACRO(initialized, PHYSFS_ERR_IS_INITIALIZED, 0); if (!externalAllocator) setDefaultAllocator(); if (allocator.Init != NULL) - BAIL_IF_MACRO(!allocator.Init(), NULL, 0); + BAIL_IF_MACRO(!allocator.Init(), ERRPASS, 0); - BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0); + BAIL_IF_MACRO(!__PHYSFS_platformInit(), ERRPASS, 0); - BAIL_IF_MACRO(!initializeMutexes(), NULL, 0); + BAIL_IF_MACRO(!initializeMutexes(), ERRPASS, 0); baseDir = calculateBaseDir(argv0); - BAIL_IF_MACRO(baseDir == NULL, NULL, 0); + BAIL_IF_MACRO(!baseDir, ERRPASS, 0); - BAIL_IF_MACRO(!appendDirSep(&baseDir), NULL, 0); + BAIL_IF_MACRO(!appendDirSep(&baseDir), ERRPASS, 0); userDir = calculateUserDir(); - if ((userDir == NULL) || (!appendDirSep(&userDir))) + if ((!userDir) || (!appendDirSep(&userDir))) { allocator.Free(baseDir); baseDir = NULL; @@ -1184,7 +1237,7 @@ int PHYSFS_init(const char *argv0) initialized = 1; /* This makes sure that the error subsystem is initialized. */ - __PHYSFS_setError(PHYSFS_getLastError()); + __PHYSFS_setError(PHYSFS_getLastErrorCode()); return 1; } /* PHYSFS_init */ @@ -1238,14 +1291,14 @@ static void freeSearchPath(void) int PHYSFS_deinit(void) { - BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); - BAIL_IF_MACRO(!__PHYSFS_platformDeinit(), NULL, 0); + BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0); + BAIL_IF_MACRO(!__PHYSFS_platformDeinit(), ERRPASS, 0); closeFileHandleList(&openWriteList); - BAIL_IF_MACRO(!PHYSFS_setWriteDir(NULL), ERR_FILES_STILL_OPEN, 0); + BAIL_IF_MACRO(!PHYSFS_setWriteDir(NULL), PHYSFS_ERR_FILES_STILL_OPEN, 0); freeSearchPath(); - freeErrorMessages(); + freeErrorStates(); if (baseDir != NULL) { @@ -1350,7 +1403,7 @@ int PHYSFS_setWriteDir(const char *newDir) if (writeDir != NULL) { - BAIL_IF_MACRO_MUTEX(!freeDirHandle(writeDir, openWriteList), NULL, + BAIL_IF_MACRO_MUTEX(!freeDirHandle(writeDir, openWriteList), ERRPASS, stateLock, 0); writeDir = NULL; } /* if */ @@ -1386,13 +1439,13 @@ static int doMount(PHYSFS_Io *io, const char *fname, { /* already in search path? */ if ((i->dirName != NULL) && (strcmp(fname, i->dirName) == 0)) - BAIL_MACRO_MUTEX(NULL, stateLock, 1); + BAIL_MACRO_MUTEX(ERRPASS, stateLock, 1); prev = i; } /* for */ } /* if */ dh = createDirHandle(io, fname, mountPoint, 0); - BAIL_IF_MACRO_MUTEX(dh == NULL, NULL, stateLock, 0); + BAIL_IF_MACRO_MUTEX(!dh, ERRPASS, stateLock, 0); if (appendToPath) { @@ -1415,7 +1468,7 @@ static int doMount(PHYSFS_Io *io, const char *fname, int PHYSFS_mountIo(PHYSFS_Io *io, const char *fname, const char *mountPoint, int appendToPath) { - BAIL_IF_MACRO(io == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(!io, PHYSFS_ERR_INVALID_ARGUMENT, 0); return doMount(io, fname, mountPoint, appendToPath); } /* PHYSFS_mountIo */ @@ -1427,10 +1480,10 @@ int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, void (*del)(void *), int retval = 0; PHYSFS_Io *io = NULL; - BAIL_IF_MACRO(buf == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(!buf, PHYSFS_ERR_INVALID_ARGUMENT, 0); io = __PHYSFS_createMemoryIo(buf, len, del); - BAIL_IF_MACRO(io == NULL, NULL, 0); + BAIL_IF_MACRO(!io, ERRPASS, 0); retval = doMount(io, fname, mountPoint, appendToPath); if (!retval) { @@ -1450,10 +1503,10 @@ int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname, int retval = 0; PHYSFS_Io *io = NULL; - BAIL_IF_MACRO(file == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(file == NULL, PHYSFS_ERR_INVALID_ARGUMENT, 0); io = __PHYSFS_createHandleIo(file); - BAIL_IF_MACRO(io == NULL, NULL, 0); + BAIL_IF_MACRO(!io, ERRPASS, 0); retval = doMount(io, fname, mountPoint, appendToPath); if (!retval) { @@ -1468,7 +1521,7 @@ int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname, int PHYSFS_mount(const char *newDir, const char *mountPoint, int appendToPath) { - BAIL_IF_MACRO(newDir == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(!newDir, PHYSFS_ERR_INVALID_ARGUMENT, 0); return doMount(NULL, newDir, mountPoint, appendToPath); } /* PHYSFS_mount */ @@ -1491,7 +1544,7 @@ int PHYSFS_unmount(const char *oldDir) DirHandle *prev = NULL; DirHandle *next = NULL; - BAIL_IF_MACRO(oldDir == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(oldDir == NULL, PHYSFS_ERR_INVALID_ARGUMENT, 0); __PHYSFS_platformGrabMutex(stateLock); for (i = searchPath; i != NULL; i = i->next) @@ -1499,7 +1552,7 @@ int PHYSFS_unmount(const char *oldDir) if (strcmp(i->dirName, oldDir) == 0) { next = i->next; - BAIL_IF_MACRO_MUTEX(!freeDirHandle(i, openReadList), NULL, + BAIL_IF_MACRO_MUTEX(!freeDirHandle(i, openReadList), ERRPASS, stateLock, 0); if (prev == NULL) @@ -1507,12 +1560,12 @@ int PHYSFS_unmount(const char *oldDir) else prev->next = next; - BAIL_MACRO_MUTEX(NULL, stateLock, 1); + BAIL_MACRO_MUTEX(ERRPASS, stateLock, 1); } /* if */ prev = i; } /* for */ - BAIL_MACRO_MUTEX(ERR_NOT_IN_SEARCH_PATH, stateLock, 0); + BAIL_MACRO_MUTEX(PHYSFS_ERR_NOT_MOUNTED, stateLock, 0); } /* PHYSFS_unmount */ @@ -1537,7 +1590,7 @@ const char *PHYSFS_getMountPoint(const char *dir) } /* for */ __PHYSFS_platformReleaseMutex(stateLock); - BAIL_MACRO(ERR_NOT_IN_SEARCH_PATH, NULL); + BAIL_MACRO(PHYSFS_ERR_NOT_MOUNTED, NULL); } /* PHYSFS_getMountPoint */ @@ -1580,7 +1633,7 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName, PHYSFS_uint64 len = 0; char *str = NULL; - BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0); + BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0); /* set write dir... */ len = (strlen(userdir) + (strlen(organization) * 2) + @@ -1588,7 +1641,7 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName, str = (char *) __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!str, PHYSFS_ERR_OUT_OF_MEMORY, 0); sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName); if (!PHYSFS_setWriteDir(str)) @@ -1611,7 +1664,7 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName, { PHYSFS_setWriteDir(NULL); /* just in case. */ __PHYSFS_smallFree(str); - BAIL_MACRO(ERR_CANT_SET_WRITE_DIR, 0); + BAIL_MACRO(PHYSFS_ERR_NO_WRITE_DIR, 0); } /* if */ } /* if */ @@ -1708,12 +1761,12 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing) size_t len = strlen(fname); assert(mntpntlen > 1); /* root mount points should be NULL. */ /* not under the mountpoint, so skip this archive. */ - BAIL_IF_MACRO(len < mntpntlen-1, ERR_NO_SUCH_PATH, 0); + BAIL_IF_MACRO(len < mntpntlen-1, PHYSFS_ERR_NO_SUCH_PATH, 0); /* !!! FIXME: Case insensitive? */ retval = strncmp(h->mountPoint, fname, mntpntlen-1); - BAIL_IF_MACRO(retval != 0, ERR_NO_SUCH_PATH, 0); + BAIL_IF_MACRO(retval != 0, PHYSFS_ERR_NO_SUCH_PATH, 0); if (len > mntpntlen-1) /* corner case... */ - BAIL_IF_MACRO(fname[mntpntlen-1] != '/', ERR_NO_SUCH_PATH, 0); + BAIL_IF_MACRO(fname[mntpntlen-1]!='/', PHYSFS_ERR_NO_SUCH_PATH, 0); fname += mntpntlen-1; /* move to start of actual archive path. */ if (*fname == '/') fname++; @@ -1736,7 +1789,8 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing) rc = (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK); if (end != NULL) *end = '/'; - BAIL_IF_MACRO(rc, ERR_SYMLINK_DISALLOWED, 0); /* insecure. */ + /* insecure path (has a disallowed symlink in it)? */ + BAIL_IF_MACRO(rc, PHYSFS_ERR_SYMLINK_FORBIDDEN, 0); /* break out early if path element is missing. */ if (!retval) @@ -1770,12 +1824,12 @@ static int doMkdir(const char *_dname, char *dname) int retval = 0; int exists = 1; /* force existance check on first path element. */ - BAIL_IF_MACRO(!sanitizePlatformIndependentPath(_dname, dname), NULL, 0); + BAIL_IF_MACRO(!sanitizePlatformIndependentPath(_dname, dname), ERRPASS, 0); __PHYSFS_platformGrabMutex(stateLock); - BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0); + BAIL_IF_MACRO_MUTEX(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, stateLock, 0); h = writeDir; - BAIL_IF_MACRO_MUTEX(!verifyPath(h, &dname, 1), NULL, stateLock, 0); + BAIL_IF_MACRO_MUTEX(!verifyPath(h, &dname, 1), ERRPASS, stateLock, 0); start = dname; while (1) @@ -1816,10 +1870,10 @@ int PHYSFS_mkdir(const char *_dname) char *dname; size_t len; - BAIL_IF_MACRO(_dname == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(!_dname, PHYSFS_ERR_INVALID_ARGUMENT, 0); len = strlen(_dname) + 1; dname = (char *) __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(dname == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!dname, PHYSFS_ERR_OUT_OF_MEMORY, 0); retval = doMkdir(_dname, dname); __PHYSFS_smallFree(dname); return retval; @@ -1830,13 +1884,13 @@ static int doDelete(const char *_fname, char *fname) { int retval; DirHandle *h; - BAIL_IF_MACRO(!sanitizePlatformIndependentPath(_fname, fname), NULL, 0); + BAIL_IF_MACRO(!sanitizePlatformIndependentPath(_fname, fname), ERRPASS, 0); __PHYSFS_platformGrabMutex(stateLock); - BAIL_IF_MACRO_MUTEX(writeDir == NULL, ERR_NO_WRITE_DIR, stateLock, 0); + BAIL_IF_MACRO_MUTEX(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, stateLock, 0); h = writeDir; - BAIL_IF_MACRO_MUTEX(!verifyPath(h, &fname, 0), NULL, stateLock, 0); + BAIL_IF_MACRO_MUTEX(!verifyPath(h, &fname, 0), ERRPASS, stateLock, 0); retval = h->funcs->remove(h->opaque, fname); __PHYSFS_platformReleaseMutex(stateLock); @@ -1850,10 +1904,10 @@ int PHYSFS_delete(const char *_fname) char *fname; size_t len; - BAIL_IF_MACRO(_fname == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0); len = strlen(_fname) + 1; fname = (char *) __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0); retval = doDelete(_fname, fname); __PHYSFS_smallFree(fname); return retval; @@ -1866,10 +1920,10 @@ const char *PHYSFS_getRealDir(const char *_fname) char *fname = NULL; size_t len; - BAIL_IF_MACRO(_fname == NULL, ERR_INVALID_ARGUMENT, NULL); + BAIL_IF_MACRO(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, NULL); len = strlen(_fname) + 1; fname = __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!fname, PHYSFS_ERR_OUT_OF_MEMORY, NULL); if (sanitizePlatformIndependentPath(_fname, fname)) { DirHandle *i; @@ -1975,7 +2029,7 @@ char **PHYSFS_enumerateFiles(const char *path) EnumStringListCallbackData ecd; memset(&ecd, '\0', sizeof (ecd)); ecd.list = (char **) allocator.Malloc(sizeof (char *)); - BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!ecd.list, PHYSFS_ERR_OUT_OF_MEMORY, NULL); PHYSFS_enumerateFilesCallback(path, enumFilesCallback, &ecd); ecd.list[ecd.size] = NULL; return ecd.list; @@ -2016,12 +2070,12 @@ void PHYSFS_enumerateFilesCallback(const char *_fname, size_t len; char *fname; - BAIL_IF_MACRO(_fname == NULL, ERR_INVALID_ARGUMENT, ) /*0*/; - BAIL_IF_MACRO(callback == NULL, ERR_INVALID_ARGUMENT, ) /*0*/; + BAIL_IF_MACRO(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, ) /*0*/; + BAIL_IF_MACRO(!callback, PHYSFS_ERR_INVALID_ARGUMENT, ) /*0*/; len = strlen(_fname) + 1; fname = (char *) __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, ) /*0*/; + BAIL_IF_MACRO(!fname, PHYSFS_ERR_OUT_OF_MEMORY, ) /*0*/; if (sanitizePlatformIndependentPath(_fname, fname)) { @@ -2058,7 +2112,7 @@ int PHYSFS_exists(const char *fname) PHYSFS_sint64 PHYSFS_getLastModTime(const char *fname) { PHYSFS_Stat statbuf; - BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), NULL, -1); + BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), ERRPASS, -1); return statbuf.modtime; } /* PHYSFS_getLastModTime */ @@ -2066,7 +2120,7 @@ PHYSFS_sint64 PHYSFS_getLastModTime(const char *fname) int PHYSFS_isDirectory(const char *fname) { PHYSFS_Stat statbuf; - BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), NULL, 0); + BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), ERRPASS, 0); return (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY); } /* PHYSFS_isDirectory */ @@ -2074,7 +2128,7 @@ int PHYSFS_isDirectory(const char *fname) int PHYSFS_isSymbolicLink(const char *fname) { PHYSFS_Stat statbuf; - BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), NULL, 0); + BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), ERRPASS, 0); return (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK); } /* PHYSFS_isSymbolicLink */ @@ -2085,10 +2139,10 @@ static PHYSFS_File *doOpenWrite(const char *_fname, int appending) size_t len; char *fname; - BAIL_IF_MACRO(_fname == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0); len = strlen(_fname) + 1; fname = (char *) __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0); if (sanitizePlatformIndependentPath(_fname, fname)) { @@ -2098,10 +2152,10 @@ static PHYSFS_File *doOpenWrite(const char *_fname, int appending) __PHYSFS_platformGrabMutex(stateLock); - GOTO_IF_MACRO(!writeDir, ERR_NO_WRITE_DIR, doOpenWriteEnd); + GOTO_IF_MACRO(!writeDir, PHYSFS_ERR_NO_WRITE_DIR, doOpenWriteEnd); h = writeDir; - GOTO_IF_MACRO(!verifyPath(h, &fname, 0), NULL, doOpenWriteEnd); + GOTO_IF_MACRO(!verifyPath(h, &fname, 0), ERRPASS, doOpenWriteEnd); f = h->funcs; if (appending) @@ -2109,13 +2163,13 @@ static PHYSFS_File *doOpenWrite(const char *_fname, int appending) else io = f->openWrite(h->opaque, fname); - GOTO_IF_MACRO(io == NULL, NULL, doOpenWriteEnd); + GOTO_IF_MACRO(!io, ERRPASS, doOpenWriteEnd); fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle)); if (fh == NULL) { io->destroy(io); - GOTO_MACRO(ERR_OUT_OF_MEMORY, doOpenWriteEnd); + GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, doOpenWriteEnd); } /* if */ else { @@ -2153,10 +2207,10 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname) char *fname; size_t len; - BAIL_IF_MACRO(_fname == NULL, ERR_INVALID_ARGUMENT, 0); + BAIL_IF_MACRO(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, 0); len = strlen(_fname) + 1; fname = (char *) __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!fname, PHYSFS_ERR_OUT_OF_MEMORY, 0); if (sanitizePlatformIndependentPath(_fname, fname)) { @@ -2166,7 +2220,7 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname) __PHYSFS_platformGrabMutex(stateLock); - GOTO_IF_MACRO(!searchPath, ERR_NO_SUCH_PATH, openReadEnd); + GOTO_IF_MACRO(!searchPath, PHYSFS_ERR_NO_SUCH_PATH, openReadEnd); /* !!! FIXME: Why aren't we using a for loop here? */ i = searchPath; @@ -2184,13 +2238,13 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname) } while ((i != NULL) && (!fileExists)); /* !!! FIXME: may not set an error if openRead didn't fail. */ - GOTO_IF_MACRO(io == NULL, NULL, openReadEnd); + GOTO_IF_MACRO(!io, ERRPASS, openReadEnd); fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle)); if (fh == NULL) { io->destroy(io); - GOTO_MACRO(ERR_OUT_OF_MEMORY, openReadEnd); + GOTO_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, openReadEnd); } /* if */ memset(fh, '\0', sizeof (FileHandle)); @@ -2253,15 +2307,15 @@ int PHYSFS_close(PHYSFS_File *_handle) /* -1 == close failure. 0 == not found. 1 == success. */ rc = closeHandleInOpenList(&openReadList, handle); - BAIL_IF_MACRO_MUTEX(rc == -1, NULL, stateLock, 0); + BAIL_IF_MACRO_MUTEX(rc == -1, ERRPASS, stateLock, 0); if (!rc) { rc = closeHandleInOpenList(&openWriteList, handle); - BAIL_IF_MACRO_MUTEX(rc == -1, NULL, stateLock, 0); + BAIL_IF_MACRO_MUTEX(rc == -1, ERRPASS, stateLock, 0); } /* if */ __PHYSFS_platformReleaseMutex(stateLock); - BAIL_IF_MACRO(!rc, ERR_NOT_A_HANDLE, 0); + BAIL_IF_MACRO(!rc, PHYSFS_ERR_INVALID_ARGUMENT, 0); return 1; } /* PHYSFS_close */ @@ -2342,11 +2396,13 @@ PHYSFS_sint64 PHYSFS_readBytes(PHYSFS_File *handle, void *buffer, const PHYSFS_uint64 maxlen = __PHYSFS_UI64(0x7FFFFFFFFFFFFFFF); #endif - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); - BAIL_IF_MACRO(len > maxlen, ERR_INVALID_ARGUMENT, -1); - BAIL_IF_MACRO(!fh->forReading, ERR_FILE_ALREADY_OPEN_W, -1); - BAIL_IF_MACRO(len == 0, NULL, 0); - if (fh->buffer != NULL) + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); + + BAIL_IF_MACRO(len > maxlen, PHYSFS_ERR_INVALID_ARGUMENT, -1); + BAIL_IF_MACRO(!fh->forReading, PHYSFS_ERR_OPEN_FOR_WRITING, -1); + BAIL_IF_MACRO(len == 0, ERRPASS, 0); + if (fh->buffer) return doBufferedRead(fh, buffer, len); return fh->io->read(fh->io, buffer, len); @@ -2367,7 +2423,7 @@ static PHYSFS_sint64 doBufferedWrite(PHYSFS_File *handle, const void *buffer, } /* if */ /* would overflow buffer. Flush and then write the new objects, too. */ - BAIL_IF_MACRO(!PHYSFS_flush(handle), NULL, -1); + BAIL_IF_MACRO(!PHYSFS_flush(handle), ERRPASS, -1); return fh->io->write(fh->io, buffer, len); } /* doBufferedWrite */ @@ -2392,11 +2448,13 @@ PHYSFS_sint64 PHYSFS_writeBytes(PHYSFS_File *handle, const void *buffer, const PHYSFS_uint64 maxlen = __PHYSFS_UI64(0x7FFFFFFFFFFFFFFF); #endif - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); - BAIL_IF_MACRO(len > maxlen, ERR_INVALID_ARGUMENT, -1); - BAIL_IF_MACRO(fh->forReading, ERR_FILE_ALREADY_OPEN_R, -1); - BAIL_IF_MACRO(len == 0, NULL, 0); - if (fh->buffer != NULL) + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); + + BAIL_IF_MACRO(len > maxlen, PHYSFS_ERR_INVALID_ARGUMENT, -1); + BAIL_IF_MACRO(fh->forReading, PHYSFS_ERR_OPEN_FOR_READING, -1); + BAIL_IF_MACRO(len == 0, ERRPASS, 0); + if (fh->buffer) return doBufferedWrite(handle, buffer, len); return fh->io->write(fh->io, buffer, len); @@ -2440,7 +2498,7 @@ PHYSFS_sint64 PHYSFS_tell(PHYSFS_File *handle) int PHYSFS_seek(PHYSFS_File *handle, PHYSFS_uint64 pos) { FileHandle *fh = (FileHandle *) handle; - BAIL_IF_MACRO(!PHYSFS_flush(handle), NULL, 0); + BAIL_IF_MACRO(!PHYSFS_flush(handle), ERRPASS, 0); if (fh->buffer && fh->forReading) { @@ -2475,10 +2533,11 @@ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 _bufsize) /* !!! FIXME: Unlocalized string. */ /* !!! FIXME: actually, why use 32 bits here? */ - BAIL_IF_MACRO(_bufsize > 0xFFFFFFFF, "buffer must fit in 32-bits", 0); + //BAIL_IF_MACRO(_bufsize > 0xFFFFFFFF, "buffer must fit in 32-bits", 0); + BAIL_IF_MACRO(_bufsize > 0xFFFFFFFF, PHYSFS_ERR_INVALID_ARGUMENT, 0); bufsize = (PHYSFS_uint32) _bufsize; - BAIL_IF_MACRO(!PHYSFS_flush(handle), NULL, 0); + BAIL_IF_MACRO(!PHYSFS_flush(handle), ERRPASS, 0); /* * For reads, we need to move the file pointer to where it would be @@ -2489,14 +2548,14 @@ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 _bufsize) { PHYSFS_uint64 pos; const PHYSFS_sint64 curpos = fh->io->tell(fh->io); - BAIL_IF_MACRO(curpos == -1, NULL, 0); + BAIL_IF_MACRO(curpos == -1, ERRPASS, 0); pos = ((curpos - fh->buffill) + fh->bufpos); - BAIL_IF_MACRO(!fh->io->seek(fh->io, pos), NULL, 0); + BAIL_IF_MACRO(!fh->io->seek(fh->io, pos), ERRPASS, 0); } /* if */ if (bufsize == 0) /* delete existing buffer. */ { - if (fh->buffer != NULL) + if (fh->buffer) { allocator.Free(fh->buffer); fh->buffer = NULL; @@ -2507,7 +2566,7 @@ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 _bufsize) { PHYSFS_uint8 *newbuf; newbuf = (PHYSFS_uint8 *) allocator.Realloc(fh->buffer, bufsize); - BAIL_IF_MACRO(newbuf == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!newbuf, PHYSFS_ERR_OUT_OF_MEMORY, 0); fh->buffer = newbuf; } /* else */ @@ -2529,7 +2588,7 @@ int PHYSFS_flush(PHYSFS_File *handle) /* dump buffer to disk. */ io = fh->io; rc = io->write(io, fh->buffer + fh->bufpos, fh->buffill - fh->bufpos); - BAIL_IF_MACRO(rc <= 0, NULL, 0); + BAIL_IF_MACRO(rc <= 0, ERRPASS, 0); fh->bufpos = fh->buffill = 0; return io->flush(io); } /* PHYSFS_flush */ @@ -2541,11 +2600,11 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat) char *fname; size_t len; - BAIL_IF_MACRO(_fname == NULL, ERR_INVALID_ARGUMENT, -1); - BAIL_IF_MACRO(stat == NULL, ERR_INVALID_ARGUMENT, -1); + BAIL_IF_MACRO(!_fname, PHYSFS_ERR_INVALID_ARGUMENT, -1); + BAIL_IF_MACRO(!stat, PHYSFS_ERR_INVALID_ARGUMENT, -1); len = strlen(_fname) + 1; fname = (char *) __PHYSFS_smallAlloc(len); - BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, -1); + BAIL_IF_MACRO(!fname, PHYSFS_ERR_OUT_OF_MEMORY, -1); /* set some sane defaults... */ stat->filesize = -1; @@ -2597,7 +2656,7 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat) int PHYSFS_setAllocator(const PHYSFS_Allocator *a) { - BAIL_IF_MACRO(initialized, ERR_IS_INITIALIZED, 0); + BAIL_IF_MACRO(initialized, PHYSFS_ERR_IS_INITIALIZED, 0); externalAllocator = (a != NULL); if (externalAllocator) memcpy(&allocator, a, sizeof (PHYSFS_Allocator)); @@ -2608,14 +2667,15 @@ int PHYSFS_setAllocator(const PHYSFS_Allocator *a) const PHYSFS_Allocator *PHYSFS_getAllocator(void) { - BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, NULL); + BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, NULL); return &allocator; } /* PHYSFS_getAllocator */ static void *mallocAllocatorMalloc(PHYSFS_uint64 s) { - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); + if (!__PHYSFS_ui64FitsAddressSpace(s)) + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); #undef malloc return malloc((size_t) s); } /* mallocAllocatorMalloc */ @@ -2623,7 +2683,8 @@ static void *mallocAllocatorMalloc(PHYSFS_uint64 s) static void *mallocAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); + if (!__PHYSFS_ui64FitsAddressSpace(s)) + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); #undef realloc return realloc(ptr, (size_t) s); } /* mallocAllocatorRealloc */ diff --git a/src/physfs.h b/src/physfs.h index 5c2cf520..0537c9fd 100644 --- a/src/physfs.h +++ b/src/physfs.h @@ -127,7 +127,7 @@ * utmost importance to some applications. * * PhysicsFS is mostly thread safe. The error messages returned by - * PHYSFS_getLastError are unique by thread, and library-state-setting + * PHYSFS_getLastError() are unique by thread, and library-state-setting * functions are mutex'd. For efficiency, individual file accesses are * not locked, so you can not safely read/write/seek/close/etc the same * file from two threads at the same time. Other race conditions are bugs @@ -607,19 +607,49 @@ PHYSFS_DECL void PHYSFS_freeList(void *listVar); * \fn const char *PHYSFS_getLastError(void) * \brief Get human-readable error information. * + * \warning As of PhysicsFS 2.1, this function has been nerfed. + * Before PhysicsFS 2.1, this function was the only way to get + * error details beyond a given function's basic return value. + * This was meant to be a human-readable string in one of several + * languages, and was not useful for application parsing. This was + * a problem, because the developer and not the user chose the + * language at compile time, and the PhysicsFS maintainers had + * to (poorly) maintain a significant amount of localization work. + * The app couldn't parse the strings, even if they counted on a + * specific language, since some were dynamically generated. + * In 2.1 and later, this always returns a static string in + * English; you may use it as a key string for your own + * localizations if you like, as we'll promise not to change + * existing error strings. Also, if your application wants to + * look at specific errors, we now offer a better option: + * use PHYSFS_getLastErrorCode() instead. + * * Get the last PhysicsFS error message as a human-readable, null-terminated - * string. This will be NULL if there's been no error since the last call to - * this function. The pointer returned by this call points to an internal + * string. This will return NULL if there's been no error since the last call + * to this function. The pointer returned by this call points to an internal * buffer. Each thread has a unique error state associated with it, but each * time a new error message is set, it will overwrite the previous one * associated with that thread. It is safe to call this function at anytime, * even before PHYSFS_init(). * - * It is not wise to expect a specific string of characters here, since the - * error message may be localized into an unfamiliar language. These strings - * are meant to be passed on directly to the user. + * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same + * thread-specific error state. Calling one will wipe out the other's + * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that + * value to PHYSFS_getErrorByCode(). + * + * As of PhysicsFS 2.1, this function only presents text in the English + * language, but the strings are static, so you can use them as keys into + * your own localization dictionary. These strings are meant to be passed on + * directly to the user. + * + * Generally, applications should only concern themselves with whether a + * given function failed; however, if your code require more specifics, you + * should use PHYSFS_getLastErrorCode() instead of this function. * * \return READ ONLY string of last error message. + * + * \sa PHYSFS_getLastErrorCode + * \sa PHYSFS_getErrorByCode */ PHYSFS_DECL const char *PHYSFS_getLastError(void); @@ -3059,6 +3089,147 @@ PHYSFS_DECL int PHYSFS_mountMemory(const void *buf, PHYSFS_uint64 len, PHYSFS_DECL int PHYSFS_mountHandle(PHYSFS_File *file, const char *fname, const char *mountPoint, int appendToPath); + +/** + * \enum PHYSFS_ErrorCode + * \brief Values that represent specific causes of failure. + * + * Most of the time, you should only concern yourself with whether a given + * operation failed or not, but there may be occasions where you plan to + * handle a specific failure case gracefully, so we provide specific error + * codes. + * + * Most of these errors are a little vague, and most aren't things you can + * fix...if there's a permission error, for example, all you can really do + * is pass that information on to the user and let them figure out how to + * handle it. In most these cases, your program should only care that it + * failed to accomplish its goals, and not care specifically why. + * + * \sa PHYSFS_getLastErrorCode + * \sa PHYSFS_getErrorByCode + */ +typedef enum __PHYSFS_ERRORCODE__ +{ + PHYSFS_ERR_OK, /**< Success; no error. */ + PHYSFS_ERR_OTHER_ERROR, /**< Error not otherwise covered here. */ + PHYSFS_ERR_OUT_OF_MEMORY, /**< Memory allocation failed. */ + PHYSFS_ERR_NOT_INITIALIZED, /**< PhysicsFS is not initialized. */ + PHYSFS_ERR_IS_INITIALIZED, /**< PhysicsFS is already initialized. */ + PHYSFS_ERR_ARGV0_IS_NULL, /**< Needed argv[0], but it is NULL. */ + PHYSFS_ERR_UNSUPPORTED, /**< Operation or feature unsupported. */ + PHYSFS_ERR_PAST_EOF, /**< Attempted to access past end of file. */ + PHYSFS_ERR_FILES_STILL_OPEN, /**< Files still open. */ + PHYSFS_ERR_INVALID_ARGUMENT, /**< Bad parameter passed to an function. */ + PHYSFS_ERR_NOT_MOUNTED, /**< Requested archive/dir not mounted. */ + PHYSFS_ERR_NO_SUCH_PATH, /**< No such file, directory, or parent. */ + PHYSFS_ERR_SYMLINK_FORBIDDEN,/**< Symlink seen when not permitted. */ + PHYSFS_ERR_NO_WRITE_DIR, /**< No write dir has been specified. */ + PHYSFS_ERR_OPEN_FOR_READING, /**< Wrote to a file opened for reading. */ + PHYSFS_ERR_OPEN_FOR_WRITING, /**< Read from a file opened for writing. */ + PHYSFS_ERR_NOT_A_FILE, /**< Needed a file, got a directory (etc). */ + PHYSFS_ERR_READ_ONLY, /**< Wrote to a read-only filesystem. */ + PHYSFS_ERR_CORRUPT, /**< Corrupted data encountered. */ + PHYSFS_ERR_SYMLINK_LOOP, /**< Infinite symbolic link loop. */ + PHYSFS_ERR_IO, /**< i/o error (hardware failure, etc). */ + PHYSFS_ERR_PERMISSION, /**< Permission denied. */ + PHYSFS_ERR_NO_SPACE, /**< No space (disk full, over quota, etc) */ + PHYSFS_ERR_BAD_FILENAME, /**< Filename is bogus/insecure. */ + PHYSFS_ERR_BUSY, /**< Tried to modify a file the OS needs. */ + PHYSFS_ERR_DIR_NOT_EMPTY, /**< Tried to delete dir with files in it. */ + PHYSFS_ERR_OS_ERROR /**< Unspecified OS-level error. */ +} PHYSFS_ErrorCode; + + +/** + * \fn PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void) + * \brief Get machine-readable error information. + * + * Get the last PhysicsFS error message as an integer value. This will return + * PHYSFS_ERR_OK if there's been no error since the last call to this + * function. Each thread has a unique error state associated with it, but + * each time a new error message is set, it will overwrite the previous one + * associated with that thread. It is safe to call this function at anytime, + * even before PHYSFS_init(). + * + * PHYSFS_getLastError() and PHYSFS_getLastErrorCode() both reset the same + * thread-specific error state. Calling one will wipe out the other's + * data. If you need both, call PHYSFS_getLastErrorCode(), then pass that + * value to PHYSFS_getErrorByCode(). + * + * Generally, applications should only concern themselves with whether a + * given function failed; however, if you require more specifics, you can + * try this function to glean information, if there's some specific problem + * you're expecting and plan to handle. But with most things that involve + * file systems, the best course of action is usually to give up, report the + * problem to the user, and let them figure out what should be done about it. + * For that, you might prefer PHYSFS_getLastError() instead. + * + * \return Enumeration value that represents last reported error. + * + * \sa PHYSFS_getErrorByCode + */ +PHYSFS_DECL PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void); + + +/** + * \fn const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code) + * \brief Get human-readable description string for a given error code. + * + * Get a static string, in UTF-8 format, that represents an English + * description of a given error code. + * + * This string is guaranteed to never change (although we may add new strings + * for new error codes in later versions of PhysicsFS), so you can use it + * for keying a localization dictionary. + * + * It is safe to call this function at anytime, even before PHYSFS_init(). + * + * These strings are meant to be passed on directly to the user. + * Generally, applications should only concern themselves with whether a + * given function failed, but not care about the specifics much. + * + * Do not attempt to free the returned strings; they are read-only and you + * don't own their memory pages. + * + * \param code Error code to convert to a string. + * \return READ ONLY string of requested error message, NULL if this + * is not a valid PhysicsFS error code. Always check for NULL if + * you might be looking up an error code that didn't exist in an + * earlier version of PhysicsFS. + * + * \sa PHYSFS_getLastErrorCode + */ +PHYSFS_DECL const char *PHYSFS_getErrorByCode(PHYSFS_ErrorCode code); + +/** + * \fn void PHYSFS_setErrorCode(PHYSFS_ErrorCode code) + * \brief Set the current thread's error code. + * + * This lets you set the value that will be returned by the next call to + * PHYSFS_getLastErrorCode(). This will replace any existing error code, + * whether set by your application or internally by PhysicsFS. + * + * Error codes are stored per-thread; what you set here will not be + * accessible to another thread. + * + * Any call into PhysicsFS may change the current error code, so any code you + * set here is somewhat fragile, and thus you shouldn't build any serious + * error reporting framework on this function. The primary goal of this + * function is to allow PHYSFS_Io implementations to set the error state, + * which generally will be passed back to your application when PhysicsFS + * makes a PHYSFS_Io call that fails internally. + * + * This function doesn't care if the error code is a value known to PhysicsFS + * or not (but PHYSFS_getErrorByCode() will return NULL for unknown values). + * The value will be reported unmolested by PHYSFS_getLastErrorCode(). + * + * \param code Error code to become the current thread's new error state. + * + * \sa PHYSFS_getLastErrorCode + * \sa PHYSFS_getErrorByCode + */ +PHYSFS_DECL void PHYSFS_setErrorCode(PHYSFS_ErrorCode code); + /* Everything above this line is part of the PhysicsFS 2.1 API. */ diff --git a/src/physfs_byteorder.c b/src/physfs_byteorder.c index 5b826a7e..b3706ffd 100644 --- a/src/physfs_byteorder.c +++ b/src/physfs_byteorder.c @@ -88,8 +88,8 @@ static inline int readAll(PHYSFS_File *file, void *val, const size_t len) #define PHYSFS_BYTEORDER_READ(datatype, swaptype) \ int PHYSFS_read##swaptype(PHYSFS_File *file, PHYSFS_##datatype *val) { \ PHYSFS_##datatype in; \ - BAIL_IF_MACRO(val == NULL, ERR_INVALID_ARGUMENT, 0); \ - BAIL_IF_MACRO(!readAll(file, &in, sizeof (in)), NULL, 0); \ + BAIL_IF_MACRO(val == NULL, PHYSFS_ERR_INVALID_ARGUMENT, 0); \ + BAIL_IF_MACRO(!readAll(file, &in, sizeof (in)), ERRPASS, 0); \ *val = PHYSFS_swap##swaptype(in); \ return 1; \ } @@ -116,7 +116,7 @@ static inline int writeAll(PHYSFS_File *f, const void *val, const size_t len) #define PHYSFS_BYTEORDER_WRITE(datatype, swaptype) \ int PHYSFS_write##swaptype(PHYSFS_File *file, PHYSFS_##datatype val) { \ const PHYSFS_##datatype out = PHYSFS_swap##swaptype(val); \ - BAIL_IF_MACRO(!writeAll(file, &out, sizeof (out)), NULL, 0); \ + BAIL_IF_MACRO(!writeAll(file, &out, sizeof (out)), ERRPASS, 0); \ return 1; \ } diff --git a/src/physfs_internal.h b/src/physfs_internal.h index 56a2e493..50ab89ca 100644 --- a/src/physfs_internal.h +++ b/src/physfs_internal.h @@ -96,615 +96,14 @@ void __PHYSFS_smallFree(void *ptr); #define free(x) Do not use free() directly. /* !!! FIXME: add alloca check here. */ -/* The LANG section. */ -/* please send questions/translations to Ryan: icculus@icculus.org. */ - -#if (!defined PHYSFS_LANG) -# define PHYSFS_LANG PHYSFS_LANG_ENGLISH -#endif - -/* All language strings are UTF-8 encoded! */ -#define PHYSFS_LANG_ENGLISH 1 /* English by Ryan C. Gordon */ -#define PHYSFS_LANG_RUSSIAN 2 /* Russian by Ed Sinjiashvili */ -#define PHYSFS_LANG_SPANISH 3 /* Spanish by Pedro J. Pérez */ -#define PHYSFS_LANG_FRENCH 4 /* French by Stéphane Peter */ -#define PHYSFS_LANG_GERMAN 5 /* German by Michael Renner */ -#define PHYSFS_LANG_PORTUGUESE_BR 6 /* pt-br by Danny Angelo Carminati Grein */ - -#if (PHYSFS_LANG == PHYSFS_LANG_ENGLISH) - #define DIR_ARCHIVE_DESCRIPTION "Non-archive, direct filesystem I/O" - #define GRP_ARCHIVE_DESCRIPTION "Build engine Groupfile format" - #define HOG_ARCHIVE_DESCRIPTION "Descent I/II HOG file format" - #define MVL_ARCHIVE_DESCRIPTION "Descent II Movielib format" - #define QPAK_ARCHIVE_DESCRIPTION "Quake I/II format" - #define ZIP_ARCHIVE_DESCRIPTION "PkZip/WinZip/Info-Zip compatible" - #define WAD_ARCHIVE_DESCRIPTION "DOOM engine format" - #define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format" - - #define ERR_IS_INITIALIZED "Already initialized" - #define ERR_NOT_INITIALIZED "Not initialized" - #define ERR_INVALID_ARGUMENT "Invalid argument" - #define ERR_FILES_STILL_OPEN "Files still open" - #define ERR_NO_DIR_CREATE "Failed to create directories" - #define ERR_OUT_OF_MEMORY "Out of memory" - #define ERR_NOT_IN_SEARCH_PATH "No such entry in search path" - #define ERR_NOT_SUPPORTED "Operation not supported" - #define ERR_UNSUPPORTED_ARCHIVE "Archive type unsupported" - #define ERR_NOT_A_HANDLE "Not a file handle" - #define ERR_INSECURE_FNAME "Insecure filename" - #define ERR_SYMLINK_DISALLOWED "Symbolic links are disabled" - #define ERR_NO_WRITE_DIR "Write directory is not set" - #define ERR_NO_SUCH_FILE "File not found" - #define ERR_NO_SUCH_PATH "Path not found" - #define ERR_NO_SUCH_VOLUME "Volume not found" - #define ERR_PAST_EOF "Past end of file" - #define ERR_ARC_IS_READ_ONLY "Archive is read-only" - #define ERR_IO_ERROR "I/O error" - #define ERR_CANT_SET_WRITE_DIR "Can't set write directory" - #define ERR_SYMLINK_LOOP "Infinite symbolic link loop" - #define ERR_COMPRESSION "(De)compression error" - #define ERR_NOT_IMPLEMENTED "Not implemented" - #define ERR_OS_ERROR "Operating system reported error" - #define ERR_FILE_EXISTS "File already exists" - #define ERR_NOT_A_FILE "Not a file" - #define ERR_NOT_A_DIR "Not a directory" - #define ERR_NOT_AN_ARCHIVE "Not an archive" - #define ERR_CORRUPTED "Corrupted archive" - #define ERR_SEEK_OUT_OF_RANGE "Seek out of range" - #define ERR_BAD_FILENAME "Bad filename" - #define ERR_PHYSFS_BAD_OS_CALL "(BUG) PhysicsFS made a bad system call" - #define ERR_ARGV0_IS_NULL "argv0 is NULL" - #define ERR_NEED_DICT "need dictionary" - #define ERR_DATA_ERROR "data error" - #define ERR_MEMORY_ERROR "memory error" - #define ERR_BUFFER_ERROR "buffer error" - #define ERR_VERSION_ERROR "version error" - #define ERR_UNKNOWN_ERROR "unknown error" - #define ERR_SEARCHPATH_TRUNC "Search path was truncated" - #define ERR_GETMODFN_TRUNC "GetModuleFileName() was truncated" - #define ERR_GETMODFN_NO_DIR "GetModuleFileName() had no dir" - #define ERR_DISK_FULL "Disk is full" - #define ERR_DIRECTORY_FULL "Directory full" - #define ERR_MACOS_GENERIC "MacOS reported error (%d)" - #define ERR_VOL_LOCKED_HW "Volume is locked through hardware" - #define ERR_VOL_LOCKED_SW "Volume is locked through software" - #define ERR_FILE_LOCKED "File is locked" - #define ERR_FILE_OR_DIR_BUSY "File/directory is busy" - #define ERR_FILE_ALREADY_OPEN_W "File already open for writing" - #define ERR_FILE_ALREADY_OPEN_R "File already open for reading" - #define ERR_INVALID_REFNUM "Invalid reference number" - #define ERR_GETTING_FILE_POS "Error getting file position" - #define ERR_VOLUME_OFFLINE "Volume is offline" - #define ERR_PERMISSION_DENIED "Permission denied" - #define ERR_VOL_ALREADY_ONLINE "Volume already online" - #define ERR_NO_SUCH_DRIVE "No such drive" - #define ERR_NOT_MAC_DISK "Not a Macintosh disk" - #define ERR_VOL_EXTERNAL_FS "Volume belongs to an external filesystem" - #define ERR_PROBLEM_RENAME "Problem during rename" - #define ERR_BAD_MASTER_BLOCK "Bad master directory block" - #define ERR_CANT_MOVE_FORBIDDEN "Attempt to move forbidden" - #define ERR_WRONG_VOL_TYPE "Wrong volume type" - #define ERR_SERVER_VOL_LOST "Server volume has been disconnected" - #define ERR_FILE_ID_NOT_FOUND "File ID not found" - #define ERR_FILE_ID_EXISTS "File ID already exists" - #define ERR_SERVER_NO_RESPOND "Server not responding" - #define ERR_USER_AUTH_FAILED "User authentication failed" - #define ERR_PWORD_EXPIRED "Password has expired on server" - #define ERR_ACCESS_DENIED "Access denied" - #define ERR_NOT_A_DOS_DISK "Not a DOS disk" - #define ERR_SHARING_VIOLATION "Sharing violation" - #define ERR_CANNOT_MAKE "Cannot make" - #define ERR_DEV_IN_USE "Device already in use" - #define ERR_OPEN_FAILED "Open failed" - #define ERR_PIPE_BUSY "Pipe is busy" - #define ERR_SHARING_BUF_EXCEEDED "Sharing buffer exceeded" - #define ERR_TOO_MANY_HANDLES "Too many open handles" - #define ERR_SEEK_ERROR "Seek error" - #define ERR_DEL_CWD "Trying to delete current working directory" - #define ERR_WRITE_PROTECT_ERROR "Write protect error" - #define ERR_WRITE_FAULT "Write fault" - #define ERR_LOCK_VIOLATION "Lock violation" - #define ERR_GEN_FAILURE "General failure" - #define ERR_UNCERTAIN_MEDIA "Uncertain media" - #define ERR_PROT_VIOLATION "Protection violation" - #define ERR_BROKEN_PIPE "Broken pipe" - -#elif (PHYSFS_LANG == PHYSFS_LANG_GERMAN) - #define DIR_ARCHIVE_DESCRIPTION "Kein Archiv, direkte Ein/Ausgabe in das Dateisystem" - #define GRP_ARCHIVE_DESCRIPTION "Build engine Groupfile format" - #define HOG_ARCHIVE_DESCRIPTION "Descent I/II HOG file format" - #define MVL_ARCHIVE_DESCRIPTION "Descent II Movielib format" - #define QPAK_ARCHIVE_DESCRIPTION "Quake I/II format" - #define ZIP_ARCHIVE_DESCRIPTION "PkZip/WinZip/Info-Zip kompatibel" - #define WAD_ARCHIVE_DESCRIPTION "DOOM engine format" /* !!! FIXME: translate this line if needed */ - #define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format" /* !!! FIXME: translate this line if needed */ - - #define ERR_IS_INITIALIZED "Bereits initialisiert" - #define ERR_NOT_INITIALIZED "Nicht initialisiert" - #define ERR_INVALID_ARGUMENT "Ungültiges Argument" - #define ERR_FILES_STILL_OPEN "Dateien noch immer geöffnet" - #define ERR_NO_DIR_CREATE "Fehler beim Erzeugen der Verzeichnisse" - #define ERR_OUT_OF_MEMORY "Kein Speicher mehr frei" - #define ERR_NOT_IN_SEARCH_PATH "Eintrag nicht im Suchpfad enthalten" - #define ERR_NOT_SUPPORTED "Befehl nicht unterstützt" - #define ERR_UNSUPPORTED_ARCHIVE "Archiv-Typ nicht unterstützt" - #define ERR_NOT_A_HANDLE "Ist kein Dateideskriptor" - #define ERR_INSECURE_FNAME "Unsicherer Dateiname" - #define ERR_SYMLINK_DISALLOWED "Symbolische Verweise deaktiviert" - #define ERR_NO_WRITE_DIR "Schreibverzeichnis ist nicht gesetzt" - #define ERR_NO_SUCH_FILE "Datei nicht gefunden" - #define ERR_NO_SUCH_PATH "Pfad nicht gefunden" - #define ERR_NO_SUCH_VOLUME "Datencontainer nicht gefunden" - #define ERR_PAST_EOF "Hinter dem Ende der Datei" - #define ERR_ARC_IS_READ_ONLY "Archiv ist schreibgeschützt" - #define ERR_IO_ERROR "Ein/Ausgabe Fehler" - #define ERR_CANT_SET_WRITE_DIR "Kann Schreibverzeichnis nicht setzen" - #define ERR_SYMLINK_LOOP "Endlosschleife durch symbolische Verweise" - #define ERR_COMPRESSION "(De)Kompressionsfehler" - #define ERR_NOT_IMPLEMENTED "Nicht implementiert" - #define ERR_OS_ERROR "Betriebssystem meldete Fehler" - #define ERR_FILE_EXISTS "Datei existiert bereits" - #define ERR_NOT_A_FILE "Ist keine Datei" - #define ERR_NOT_A_DIR "Ist kein Verzeichnis" - #define ERR_NOT_AN_ARCHIVE "Ist kein Archiv" - #define ERR_CORRUPTED "Beschädigtes Archiv" - #define ERR_SEEK_OUT_OF_RANGE "Suche war ausserhalb der Reichweite" - #define ERR_BAD_FILENAME "Unzulässiger Dateiname" - #define ERR_PHYSFS_BAD_OS_CALL "(BUG) PhysicsFS verursachte einen ungültigen Systemaufruf" - #define ERR_ARGV0_IS_NULL "argv0 ist NULL" - #define ERR_NEED_DICT "brauche Wörterbuch" - #define ERR_DATA_ERROR "Datenfehler" - #define ERR_MEMORY_ERROR "Speicherfehler" - #define ERR_BUFFER_ERROR "Bufferfehler" - #define ERR_VERSION_ERROR "Versionskonflikt" - #define ERR_UNKNOWN_ERROR "Unbekannter Fehler" - #define ERR_SEARCHPATH_TRUNC "Suchpfad war abgeschnitten" - #define ERR_GETMODFN_TRUNC "GetModuleFileName() war abgeschnitten" - #define ERR_GETMODFN_NO_DIR "GetModuleFileName() bekam kein Verzeichnis" - #define ERR_DISK_FULL "Laufwerk ist voll" - #define ERR_DIRECTORY_FULL "Verzeichnis ist voll" - #define ERR_MACOS_GENERIC "MacOS meldete Fehler (%d)" - #define ERR_VOL_LOCKED_HW "Datencontainer ist durch Hardware gesperrt" - #define ERR_VOL_LOCKED_SW "Datencontainer ist durch Software gesperrt" - #define ERR_FILE_LOCKED "Datei ist gesperrt" - #define ERR_FILE_OR_DIR_BUSY "Datei/Verzeichnis ist beschäftigt" - #define ERR_FILE_ALREADY_OPEN_W "Datei schon im Schreibmodus geöffnet" - #define ERR_FILE_ALREADY_OPEN_R "Datei schon im Lesemodus geöffnet" - #define ERR_INVALID_REFNUM "Ungültige Referenznummer" - #define ERR_GETTING_FILE_POS "Fehler beim Finden der Dateiposition" - #define ERR_VOLUME_OFFLINE "Datencontainer ist offline" - #define ERR_PERMISSION_DENIED "Zugriff verweigert" - #define ERR_VOL_ALREADY_ONLINE "Datencontainer ist bereits online" - #define ERR_NO_SUCH_DRIVE "Laufwerk nicht vorhanden" - #define ERR_NOT_MAC_DISK "Ist kein Macintosh Laufwerk" - #define ERR_VOL_EXTERNAL_FS "Datencontainer liegt auf einem externen Dateisystem" - #define ERR_PROBLEM_RENAME "Fehler beim Umbenennen" - #define ERR_BAD_MASTER_BLOCK "Beschädigter Hauptverzeichnisblock" - #define ERR_CANT_MOVE_FORBIDDEN "Verschieben nicht erlaubt" - #define ERR_WRONG_VOL_TYPE "Falscher Datencontainer-Typ" - #define ERR_SERVER_VOL_LOST "Datencontainer am Server wurde getrennt" - #define ERR_FILE_ID_NOT_FOUND "Dateikennung nicht gefunden" - #define ERR_FILE_ID_EXISTS "Dateikennung existiert bereits" - #define ERR_SERVER_NO_RESPOND "Server antwortet nicht" - #define ERR_USER_AUTH_FAILED "Benutzerauthentifizierung fehlgeschlagen" - #define ERR_PWORD_EXPIRED "Passwort am Server ist abgelaufen" - #define ERR_ACCESS_DENIED "Zugriff verweigert" - #define ERR_NOT_A_DOS_DISK "Ist kein DOS-Laufwerk" - #define ERR_SHARING_VIOLATION "Zugriffsverletzung" - #define ERR_CANNOT_MAKE "Kann nicht erzeugen" - #define ERR_DEV_IN_USE "Gerät wird bereits benutzt" - #define ERR_OPEN_FAILED "Öffnen fehlgeschlagen" - #define ERR_PIPE_BUSY "Pipeverbindung ist belegt" - #define ERR_SHARING_BUF_EXCEEDED "Zugriffsbuffer überschritten" - #define ERR_TOO_MANY_HANDLES "Zu viele offene Dateien" - #define ERR_SEEK_ERROR "Fehler beim Suchen" - #define ERR_DEL_CWD "Aktuelles Arbeitsverzeichnis darf nicht gelöscht werden" - #define ERR_WRITE_PROTECT_ERROR "Schreibschutzfehler" - #define ERR_WRITE_FAULT "Schreibfehler" - #define ERR_LOCK_VIOLATION "Sperrverletzung" - #define ERR_GEN_FAILURE "Allgemeiner Fehler" - #define ERR_UNCERTAIN_MEDIA "Unsicheres Medium" - #define ERR_PROT_VIOLATION "Schutzverletzung" - #define ERR_BROKEN_PIPE "Pipeverbindung unterbrochen" - -#elif (PHYSFS_LANG == PHYSFS_LANG_RUSSIAN) - #define DIR_ARCHIVE_DESCRIPTION "Не архив, непосредственный ввод/вывод файловой системы" - #define GRP_ARCHIVE_DESCRIPTION "Формат группового файла Build engine" - #define HOG_ARCHIVE_DESCRIPTION "Descent I/II HOG file format" - #define MVL_ARCHIVE_DESCRIPTION "Descent II Movielib format" - #define ZIP_ARCHIVE_DESCRIPTION "PkZip/WinZip/Info-Zip совместимый" - #define WAD_ARCHIVE_DESCRIPTION "DOOM engine format" /* !!! FIXME: translate this line if needed */ - #define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format" /* !!! FIXME: translate this line if needed */ - - #define ERR_IS_INITIALIZED "Уже инициализирован" - #define ERR_NOT_INITIALIZED "Не инициализирован" - #define ERR_INVALID_ARGUMENT "Неверный аргумент" - #define ERR_FILES_STILL_OPEN "Файлы еще открыты" - #define ERR_NO_DIR_CREATE "Не могу создать каталоги" - #define ERR_OUT_OF_MEMORY "Кончилась память" - #define ERR_NOT_IN_SEARCH_PATH "Нет такого элемента в пути поиска" - #define ERR_NOT_SUPPORTED "Операция не поддерживается" - #define ERR_UNSUPPORTED_ARCHIVE "Архивы такого типа не поддерживаются" - #define ERR_NOT_A_HANDLE "Не файловый дескриптор" - #define ERR_INSECURE_FNAME "Небезопасное имя файла" - #define ERR_SYMLINK_DISALLOWED "Символьные ссылки отключены" - #define ERR_NO_WRITE_DIR "Каталог для записи не установлен" - #define ERR_NO_SUCH_FILE "Файл не найден" - #define ERR_NO_SUCH_PATH "Путь не найден" - #define ERR_NO_SUCH_VOLUME "Том не найден" - #define ERR_PAST_EOF "За концом файла" - #define ERR_ARC_IS_READ_ONLY "Архив только для чтения" - #define ERR_IO_ERROR "Ошибка ввода/вывода" - #define ERR_CANT_SET_WRITE_DIR "Не могу установить каталог для записи" - #define ERR_SYMLINK_LOOP "Бесконечный цикл символьной ссылки" - #define ERR_COMPRESSION "Ошибка (Рас)паковки" - #define ERR_NOT_IMPLEMENTED "Не реализовано" - #define ERR_OS_ERROR "Операционная система сообщила ошибку" - #define ERR_FILE_EXISTS "Файл уже существует" - #define ERR_NOT_A_FILE "Не файл" - #define ERR_NOT_A_DIR "Не каталог" - #define ERR_NOT_AN_ARCHIVE "Не архив" - #define ERR_CORRUPTED "Поврежденный архив" - #define ERR_SEEK_OUT_OF_RANGE "Позиционирование за пределы" - #define ERR_BAD_FILENAME "Неверное имя файла" - #define ERR_PHYSFS_BAD_OS_CALL "(BUG) PhysicsFS выполнила неверный системный вызов" - #define ERR_ARGV0_IS_NULL "argv0 is NULL" - #define ERR_NEED_DICT "нужен словарь" - #define ERR_DATA_ERROR "ошибка данных" - #define ERR_MEMORY_ERROR "ошибка памяти" - #define ERR_BUFFER_ERROR "ошибка буфера" - #define ERR_VERSION_ERROR "ошибка версии" - #define ERR_UNKNOWN_ERROR "неизвестная ошибка" - #define ERR_SEARCHPATH_TRUNC "Путь поиска обрезан" - #define ERR_GETMODFN_TRUNC "GetModuleFileName() обрезан" - #define ERR_GETMODFN_NO_DIR "GetModuleFileName() не получил каталог" - #define ERR_DISK_FULL "Диск полон" - #define ERR_DIRECTORY_FULL "Каталог полон" - #define ERR_MACOS_GENERIC "MacOS сообщила ошибку (%d)" - #define ERR_VOL_LOCKED_HW "Том блокирован аппаратно" - #define ERR_VOL_LOCKED_SW "Том блокирован программно" - #define ERR_FILE_LOCKED "Файл заблокирован" - #define ERR_FILE_OR_DIR_BUSY "Файл/каталог занят" - #define ERR_FILE_ALREADY_OPEN_W "Файл уже открыт на запись" - #define ERR_FILE_ALREADY_OPEN_R "Файл уже открыт на чтение" - #define ERR_INVALID_REFNUM "Неверное количество ссылок" - #define ERR_GETTING_FILE_POS "Ошибка при получении позиции файла" - #define ERR_VOLUME_OFFLINE "Том отсоединен" - #define ERR_PERMISSION_DENIED "Отказано в разрешении" - #define ERR_VOL_ALREADY_ONLINE "Том уже подсоединен" - #define ERR_NO_SUCH_DRIVE "Нет такого диска" - #define ERR_NOT_MAC_DISK "Не диск Macintosh" - #define ERR_VOL_EXTERNAL_FS "Том принадлежит внешней файловой системе" - #define ERR_PROBLEM_RENAME "Проблема при переименовании" - #define ERR_BAD_MASTER_BLOCK "Плохой главный блок каталога" - #define ERR_CANT_MOVE_FORBIDDEN "Попытка переместить запрещена" - #define ERR_WRONG_VOL_TYPE "Неверный тип тома" - #define ERR_SERVER_VOL_LOST "Серверный том был отсоединен" - #define ERR_FILE_ID_NOT_FOUND "Идентификатор файла не найден" - #define ERR_FILE_ID_EXISTS "Идентификатор файла уже существует" - #define ERR_SERVER_NO_RESPOND "Сервер не отвечает" - #define ERR_USER_AUTH_FAILED "Идентификация пользователя не удалась" - #define ERR_PWORD_EXPIRED "Пароль на сервере устарел" - #define ERR_ACCESS_DENIED "Отказано в доступе" - #define ERR_NOT_A_DOS_DISK "Не диск DOS" - #define ERR_SHARING_VIOLATION "Нарушение совместного доступа" - #define ERR_CANNOT_MAKE "Не могу собрать" - #define ERR_DEV_IN_USE "Устройство уже используется" - #define ERR_OPEN_FAILED "Открытие не удалось" - #define ERR_PIPE_BUSY "Конвейер занят" - #define ERR_SHARING_BUF_EXCEEDED "Разделяемый буфер переполнен" - #define ERR_TOO_MANY_HANDLES "Слишком много открытых дескрипторов" - #define ERR_SEEK_ERROR "Ошибка позиционирования" - #define ERR_DEL_CWD "Попытка удалить текущий рабочий каталог" - #define ERR_WRITE_PROTECT_ERROR "Ошибка защиты записи" - #define ERR_WRITE_FAULT "Ошибка записи" - #define ERR_LOCK_VIOLATION "Нарушение блокировки" - #define ERR_GEN_FAILURE "Общий сбой" - #define ERR_UNCERTAIN_MEDIA "Неопределенный носитель" - #define ERR_PROT_VIOLATION "Нарушение защиты" - #define ERR_BROKEN_PIPE "Сломанный конвейер" - - -#elif (PHYSFS_LANG == PHYSFS_LANG_FRENCH) - #define DIR_ARCHIVE_DESCRIPTION "Pas d'archive, E/S directes sur système de fichiers" - #define GRP_ARCHIVE_DESCRIPTION "Format Groupfile du moteur Build" - #define HOG_ARCHIVE_DESCRIPTION "Descent I/II HOG file format" - #define MVL_ARCHIVE_DESCRIPTION "Descent II Movielib format" - #define QPAK_ARCHIVE_DESCRIPTION "Quake I/II format" - #define ZIP_ARCHIVE_DESCRIPTION "Compatible PkZip/WinZip/Info-Zip" - #define WAD_ARCHIVE_DESCRIPTION "Format WAD du moteur DOOM" - #define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format" /* !!! FIXME: translate this line if needed */ - - #define ERR_IS_INITIALIZED "Déjà initialisé" - #define ERR_NOT_INITIALIZED "Non initialisé" - #define ERR_INVALID_ARGUMENT "Argument invalide" - #define ERR_FILES_STILL_OPEN "Fichiers encore ouverts" - #define ERR_NO_DIR_CREATE "Echec de la création de répertoires" - #define ERR_OUT_OF_MEMORY "A court de mémoire" - #define ERR_NOT_IN_SEARCH_PATH "Aucune entrée dans le chemin de recherche" - #define ERR_NOT_SUPPORTED "Opération non supportée" - #define ERR_UNSUPPORTED_ARCHIVE "Type d'archive non supportée" - #define ERR_NOT_A_HANDLE "Pas un descripteur de fichier" - #define ERR_INSECURE_FNAME "Nom de fichier dangereux" - #define ERR_SYMLINK_DISALLOWED "Les liens symboliques sont désactivés" - #define ERR_NO_WRITE_DIR "Le répertoire d'écriture n'est pas spécifié" - #define ERR_NO_SUCH_FILE "Fichier non trouvé" - #define ERR_NO_SUCH_PATH "Chemin non trouvé" - #define ERR_NO_SUCH_VOLUME "Volume non trouvé" - #define ERR_PAST_EOF "Au-delà de la fin du fichier" - #define ERR_ARC_IS_READ_ONLY "L'archive est en lecture seule" - #define ERR_IO_ERROR "Erreur E/S" - #define ERR_CANT_SET_WRITE_DIR "Ne peut utiliser le répertoire d'écriture" - #define ERR_SYMLINK_LOOP "Boucle infinie dans les liens symboliques" - #define ERR_COMPRESSION "Erreur de (dé)compression" - #define ERR_NOT_IMPLEMENTED "Non implémenté" - #define ERR_OS_ERROR "Erreur rapportée par le système d'exploitation" - #define ERR_FILE_EXISTS "Le fichier existe déjà" - #define ERR_NOT_A_FILE "Pas un fichier" - #define ERR_NOT_A_DIR "Pas un répertoire" - #define ERR_NOT_AN_ARCHIVE "Pas une archive" - #define ERR_CORRUPTED "Archive corrompue" - #define ERR_SEEK_OUT_OF_RANGE "Pointeur de fichier hors de portée" - #define ERR_BAD_FILENAME "Mauvais nom de fichier" - #define ERR_PHYSFS_BAD_OS_CALL "(BOGUE) PhysicsFS a fait un mauvais appel système, le salaud" - #define ERR_ARGV0_IS_NULL "argv0 est NULL" - #define ERR_NEED_DICT "a besoin du dico" - #define ERR_DATA_ERROR "erreur de données" - #define ERR_MEMORY_ERROR "erreur mémoire" - #define ERR_BUFFER_ERROR "erreur tampon" - #define ERR_VERSION_ERROR "erreur de version" - #define ERR_UNKNOWN_ERROR "erreur inconnue" - #define ERR_SEARCHPATH_TRUNC "Le chemin de recherche a été tronqué" - #define ERR_GETMODFN_TRUNC "GetModuleFileName() a été tronqué" - #define ERR_GETMODFN_NO_DIR "GetModuleFileName() n'a pas de répertoire" - #define ERR_DISK_FULL "Disque plein" - #define ERR_DIRECTORY_FULL "Répertoire plein" - #define ERR_MACOS_GENERIC "Erreur rapportée par MacOS (%d)" - #define ERR_VOL_LOCKED_HW "Le volume est verrouillé matériellement" - #define ERR_VOL_LOCKED_SW "Le volume est verrouillé par logiciel" - #define ERR_FILE_LOCKED "Fichier verrouillé" - #define ERR_FILE_OR_DIR_BUSY "Fichier/répertoire occupé" - #define ERR_FILE_ALREADY_OPEN_W "Fichier déjà ouvert en écriture" - #define ERR_FILE_ALREADY_OPEN_R "Fichier déjà ouvert en lecture" - #define ERR_INVALID_REFNUM "Numéro de référence invalide" - #define ERR_GETTING_FILE_POS "Erreur lors de l'obtention de la position du pointeur de fichier" - #define ERR_VOLUME_OFFLINE "Le volume n'est pas en ligne" - #define ERR_PERMISSION_DENIED "Permission refusée" - #define ERR_VOL_ALREADY_ONLINE "Volumé déjà en ligne" - #define ERR_NO_SUCH_DRIVE "Lecteur inexistant" - #define ERR_NOT_MAC_DISK "Pas un disque Macintosh" - #define ERR_VOL_EXTERNAL_FS "Le volume appartient à un système de fichiers externe" - #define ERR_PROBLEM_RENAME "Problème lors du renommage" - #define ERR_BAD_MASTER_BLOCK "Mauvais block maitre de répertoire" - #define ERR_CANT_MOVE_FORBIDDEN "Essai de déplacement interdit" - #define ERR_WRONG_VOL_TYPE "Mauvais type de volume" - #define ERR_SERVER_VOL_LOST "Le volume serveur a été déconnecté" - #define ERR_FILE_ID_NOT_FOUND "Identificateur de fichier non trouvé" - #define ERR_FILE_ID_EXISTS "Identificateur de fichier existe déjà" - #define ERR_SERVER_NO_RESPOND "Le serveur ne répond pas" - #define ERR_USER_AUTH_FAILED "Authentification de l'utilisateur échouée" - #define ERR_PWORD_EXPIRED "Le mot de passe a expiré sur le serveur" - #define ERR_ACCESS_DENIED "Accès refusé" - #define ERR_NOT_A_DOS_DISK "Pas un disque DOS" - #define ERR_SHARING_VIOLATION "Violation de partage" - #define ERR_CANNOT_MAKE "Ne peut faire" - #define ERR_DEV_IN_USE "Périphérique déjà en utilisation" - #define ERR_OPEN_FAILED "Ouverture échouée" - #define ERR_PIPE_BUSY "Le tube est occupé" - #define ERR_SHARING_BUF_EXCEEDED "Tampon de partage dépassé" - #define ERR_TOO_MANY_HANDLES "Trop de descripteurs ouverts" - #define ERR_SEEK_ERROR "Erreur de positionement" - #define ERR_DEL_CWD "Essai de supprimer le répertoire courant" - #define ERR_WRITE_PROTECT_ERROR "Erreur de protection en écriture" - #define ERR_WRITE_FAULT "Erreur d'écriture" - #define ERR_LOCK_VIOLATION "Violation de verrou" - #define ERR_GEN_FAILURE "Echec général" - #define ERR_UNCERTAIN_MEDIA "Média incertain" - #define ERR_PROT_VIOLATION "Violation de protection" - #define ERR_BROKEN_PIPE "Tube cassé" - -#elif (PHYSFS_LANG == PHYSFS_LANG_PORTUGUESE_BR) - #define DIR_ARCHIVE_DESCRIPTION "Não arquivo, E/S sistema de arquivos direto" - #define GRP_ARCHIVE_DESCRIPTION "Formato Groupfile do engine Build" - #define HOG_ARCHIVE_DESCRIPTION "Formato Descent I/II HOG file" - #define MVL_ARCHIVE_DESCRIPTION "Formato Descent II Movielib" - #define QPAK_ARCHIVE_DESCRIPTION "Formato Quake I/II" - #define ZIP_ARCHIVE_DESCRIPTION "Formato compatível PkZip/WinZip/Info-Zip" - #define WAD_ARCHIVE_DESCRIPTION "Formato WAD do engine DOOM" - #define WAD_ARCHIVE_DESCRIPTION "DOOM engine format" /* !!! FIXME: translate this line if needed */ - #define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format" /* !!! FIXME: translate this line if needed */ - - #define ERR_IS_INITIALIZED "Já inicializado" - #define ERR_NOT_INITIALIZED "Não inicializado" - #define ERR_INVALID_ARGUMENT "Argumento inválido" - #define ERR_FILES_STILL_OPEN "Arquivos ainda abertos" - #define ERR_NO_DIR_CREATE "Falha na criação de diretórios" - #define ERR_OUT_OF_MEMORY "Memória insuficiente" - #define ERR_NOT_IN_SEARCH_PATH "Entrada não encontrada no caminho de busca" - #define ERR_NOT_SUPPORTED "Operação não suportada" - #define ERR_UNSUPPORTED_ARCHIVE "Tipo de arquivo não suportado" - #define ERR_NOT_A_HANDLE "Não é um handler de arquivo" - #define ERR_INSECURE_FNAME "Nome de arquivo inseguro" - #define ERR_SYMLINK_DISALLOWED "Links simbólicos desabilitados" - #define ERR_NO_WRITE_DIR "Diretório de escrita não definido" - #define ERR_NO_SUCH_FILE "Arquivo não encontrado" - #define ERR_NO_SUCH_PATH "Caminho não encontrado" - #define ERR_NO_SUCH_VOLUME "Volume não encontrado" - #define ERR_PAST_EOF "Passou o fim do arquivo" - #define ERR_ARC_IS_READ_ONLY "Arquivo é somente de leitura" - #define ERR_IO_ERROR "Erro de E/S" - #define ERR_CANT_SET_WRITE_DIR "Não foi possível definir diretório de escrita" - #define ERR_SYMLINK_LOOP "Loop infinito de link simbólico" - #define ERR_COMPRESSION "Erro de (Des)compressão" - #define ERR_NOT_IMPLEMENTED "Não implementado" - #define ERR_OS_ERROR "Erro reportado pelo Sistema Operacional" - #define ERR_FILE_EXISTS "Arquivo já existente" - #define ERR_NOT_A_FILE "Não é um arquivo" - #define ERR_NOT_A_DIR "Não é um diretório" - #define ERR_NOT_AN_ARCHIVE "Não é um pacote" - #define ERR_CORRUPTED "Pacote corrompido" - #define ERR_SEEK_OUT_OF_RANGE "Posicionamento além do tamanho" - #define ERR_BAD_FILENAME "Nome de arquivo inválido" - #define ERR_PHYSFS_BAD_OS_CALL "(BUG) PhysicsFS realizou uma chamada de sistema inválida" - #define ERR_ARGV0_IS_NULL "argv0 é NULL" - #define ERR_NEED_DICT "precisa de diretório" - #define ERR_DATA_ERROR "erro nos dados" - #define ERR_MEMORY_ERROR "erro de memória" - #define ERR_BUFFER_ERROR "erro de buffer" - #define ERR_VERSION_ERROR "erro na version" - #define ERR_UNKNOWN_ERROR "erro desconhecido" - #define ERR_SEARCHPATH_TRUNC "Caminho de procura quebrado" - #define ERR_GETMODFN_TRUNC "GetModuleFileName() foi quebrado" - #define ERR_GETMODFN_NO_DIR "GetModuleFileName() nao teve diretório" - #define ERR_DISK_FULL "Disco cheio" - #define ERR_DIRECTORY_FULL "Diretório cheio" - #define ERR_MACOS_GENERIC "MacOS reportou um erro (%d)" - #define ERR_VOL_LOCKED_HW "Volume travado por hardware" - #define ERR_VOL_LOCKED_SW "Volume travado por software" - #define ERR_FILE_LOCKED "Arquivo travado" - #define ERR_FILE_OR_DIR_BUSY "Arquivo/Diretório está em uso" - #define ERR_FILE_ALREADY_OPEN_W "Arquivo já aberto para escrita" - #define ERR_FILE_ALREADY_OPEN_R "Arquivo já aberto para leitura" - #define ERR_INVALID_REFNUM "Número de referência" - #define ERR_GETTING_FILE_POS "Erro ao tentar obter posição do arquivo" - #define ERR_VOLUME_OFFLINE "Volume está indisponível" - #define ERR_PERMISSION_DENIED "Permissão negada" - #define ERR_VOL_ALREADY_ONLINE "Volume disponível" - #define ERR_NO_SUCH_DRIVE "Drive inexistente" - #define ERR_NOT_MAC_DISK "Não é um disco Macintosh" - #define ERR_VOL_EXTERNAL_FS "Volume pertence a um sistema de arquivos externo" - #define ERR_PROBLEM_RENAME "Problema durante renomeação" - #define ERR_BAD_MASTER_BLOCK "Bloco master do diretório inválido" - #define ERR_CANT_MOVE_FORBIDDEN "Tentativa de mover proibida" - #define ERR_WRONG_VOL_TYPE "Tipo inválido de volume" - #define ERR_SERVER_VOL_LOST "Volume servidor desconectado" - #define ERR_FILE_ID_NOT_FOUND "ID de Arquivo não encontrado" - #define ERR_FILE_ID_EXISTS "ID de Arquivo já existente" - #define ERR_SERVER_NO_RESPOND "Servidor não respondendo" - #define ERR_USER_AUTH_FAILED "Autenticação de usuário falhada" - #define ERR_PWORD_EXPIRED "Password foi expirada no servidor" - #define ERR_ACCESS_DENIED "Accesso negado" - #define ERR_NOT_A_DOS_DISK "Não é um disco DOS" - #define ERR_SHARING_VIOLATION "Violação de compartilhamento" - #define ERR_CANNOT_MAKE "Não pode ser feito" - #define ERR_DEV_IN_USE "Device já em uso" - #define ERR_OPEN_FAILED "Falaha na abertura" - #define ERR_PIPE_BUSY "Fila ocupada" - #define ERR_SHARING_BUF_EXCEEDED "Buffer de compartilhamento excedeu" - #define ERR_TOO_MANY_HANDLES "Muitos handles abertos" - #define ERR_SEEK_ERROR "Erro de posicionamento" - #define ERR_DEL_CWD "Tentando remover diretório de trabalho atual" - #define ERR_WRITE_PROTECT_ERROR "Erro de proteção de escrita" - #define ERR_WRITE_FAULT "Erro de escrita" - #define ERR_LOCK_VIOLATION "Violação de trava" - #define ERR_GEN_FAILURE "Falha geral" - #define ERR_UNCERTAIN_MEDIA "Media incerta" - #define ERR_PROT_VIOLATION "Violação de proteção" - #define ERR_BROKEN_PIPE "Fila quebrada" - -#elif (PHYSFS_LANG == PHYSFS_LANG_SPANISH) - #define DIR_ARCHIVE_DESCRIPTION "No es un archivo, E/S directa al sistema de ficheros" - #define GRP_ARCHIVE_DESCRIPTION "Formato Build engine Groupfile" - #define HOG_ARCHIVE_DESCRIPTION "Formato Descent I/II HOG file" - #define MVL_ARCHIVE_DESCRIPTION "Formato Descent II Movielib" - #define QPAK_ARCHIVE_DESCRIPTION "Formato Quake I/II" - #define ZIP_ARCHIVE_DESCRIPTION "Compatible con PkZip/WinZip/Info-Zip" - #define WAD_ARCHIVE_DESCRIPTION "DOOM engine format" /* !!! FIXME: translate this line if needed */ - #define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format" /* !!! FIXME: translate this line if needed */ - - #define ERR_IS_INITIALIZED "Ya estaba inicializado" - #define ERR_NOT_INITIALIZED "No está inicializado" - #define ERR_INVALID_ARGUMENT "Argumento inválido" - #define ERR_FILES_STILL_OPEN "Archivos aún abiertos" - #define ERR_NO_DIR_CREATE "Fallo al crear los directorios" - #define ERR_OUT_OF_MEMORY "Memoria agotada" - #define ERR_NOT_IN_SEARCH_PATH "No existe tal entrada en la ruta de búsqueda" - #define ERR_NOT_SUPPORTED "Operación no soportada" - #define ERR_UNSUPPORTED_ARCHIVE "Tipo de archivo no soportado" - #define ERR_NOT_A_HANDLE "No es un manejador de ficheo (file handle)" - #define ERR_INSECURE_FNAME "Nombre de archivo inseguro" - #define ERR_SYMLINK_DISALLOWED "Los enlaces simbólicos están desactivados" - #define ERR_NO_WRITE_DIR "No has configurado un directorio de escritura" - #define ERR_NO_SUCH_FILE "Archivo no encontrado" - #define ERR_NO_SUCH_PATH "Ruta no encontrada" - #define ERR_NO_SUCH_VOLUME "Volumen no encontrado" - #define ERR_PAST_EOF "Te pasaste del final del archivo" - #define ERR_ARC_IS_READ_ONLY "El archivo es de sólo lectura" - #define ERR_IO_ERROR "Error E/S" - #define ERR_CANT_SET_WRITE_DIR "No puedo configurar el directorio de escritura" - #define ERR_SYMLINK_LOOP "Bucle infnito de enlaces simbólicos" - #define ERR_COMPRESSION "Error de (des)compresión" - #define ERR_NOT_IMPLEMENTED "No implementado" - #define ERR_OS_ERROR "El sistema operativo ha devuelto un error" - #define ERR_FILE_EXISTS "El archivo ya existe" - #define ERR_NOT_A_FILE "No es un archivo" - #define ERR_NOT_A_DIR "No es un directorio" - #define ERR_NOT_AN_ARCHIVE "No es un archivo" - #define ERR_CORRUPTED "Archivo corrupto" - #define ERR_SEEK_OUT_OF_RANGE "Búsqueda fuera de rango" - #define ERR_BAD_FILENAME "Nombre de archivo incorrecto" - #define ERR_PHYSFS_BAD_OS_CALL "(BUG) PhysicsFS ha hecho una llamada incorrecta al sistema" - #define ERR_ARGV0_IS_NULL "argv0 es NULL" - #define ERR_NEED_DICT "necesito diccionario" - #define ERR_DATA_ERROR "error de datos" - #define ERR_MEMORY_ERROR "error de memoria" - #define ERR_BUFFER_ERROR "error de buffer" - #define ERR_VERSION_ERROR "error de versión" - #define ERR_UNKNOWN_ERROR "error desconocido" - #define ERR_SEARCHPATH_TRUNC "La ruta de búsqueda ha sido truncada" - #define ERR_GETMODFN_TRUNC "GetModuleFileName() ha sido truncado" - #define ERR_GETMODFN_NO_DIR "GetModuleFileName() no tenia directorio" - #define ERR_DISK_FULL "El disco está lleno" - #define ERR_DIRECTORY_FULL "El directorio está lleno" - #define ERR_MACOS_GENERIC "MacOS ha devuelto un error (%d)" - #define ERR_VOL_LOCKED_HW "El volumen está bloqueado por el hardware" - #define ERR_VOL_LOCKED_SW "El volumen está bloqueado por el software" - #define ERR_FILE_LOCKED "El archivo está bloqueado" - #define ERR_FILE_OR_DIR_BUSY "Fichero o directorio ocupados" - #define ERR_FILE_ALREADY_OPEN_W "Fichero ya abierto para escritura" - #define ERR_FILE_ALREADY_OPEN_R "Fichero ya abierto para lectura" - #define ERR_INVALID_REFNUM "El número de referencia no es válido" - #define ERR_GETTING_FILE_POS "Error al tomar la posición del fichero" - #define ERR_VOLUME_OFFLINE "El volumen está desconectado" - #define ERR_PERMISSION_DENIED "Permiso denegado" - #define ERR_VOL_ALREADY_ONLINE "El volumen ya estaba conectado" - #define ERR_NO_SUCH_DRIVE "No existe tal unidad" - #define ERR_NOT_MAC_DISK "No es un disco Macintosh" - #define ERR_VOL_EXTERNAL_FS "El volumen pertence a un sistema de ficheros externo" - #define ERR_PROBLEM_RENAME "Problemas al renombrar" - #define ERR_BAD_MASTER_BLOCK "Bloque maestro de directorios incorrecto" - #define ERR_CANT_MOVE_FORBIDDEN "Intento de mover forbidden" - #define ERR_WRONG_VOL_TYPE "Tipo de volumen incorrecto" - #define ERR_SERVER_VOL_LOST "El servidor de volúmenes ha sido desconectado" - #define ERR_FILE_ID_NOT_FOUND "Identificador de archivo no encontrado" - #define ERR_FILE_ID_EXISTS "El identificador de archivo ya existe" - #define ERR_SERVER_NO_RESPOND "El servidor no responde" - #define ERR_USER_AUTH_FAILED "Fallo al autentificar el usuario" - #define ERR_PWORD_EXPIRED "La Password en el servidor ha caducado" - #define ERR_ACCESS_DENIED "Acceso denegado" - #define ERR_NOT_A_DOS_DISK "No es un disco de DOS" - #define ERR_SHARING_VIOLATION "Violación al compartir" - #define ERR_CANNOT_MAKE "No puedo hacer make" - #define ERR_DEV_IN_USE "El dispositivo ya estaba en uso" - #define ERR_OPEN_FAILED "Fallo al abrir" - #define ERR_PIPE_BUSY "Tubería ocupada" - #define ERR_SHARING_BUF_EXCEEDED "Buffer de compartición sobrepasado" - #define ERR_TOO_MANY_HANDLES "Demasiados manejadores (handles)" - #define ERR_SEEK_ERROR "Error de búsqueda" - #define ERR_DEL_CWD "Intentando borrar el directorio de trabajo actual" - #define ERR_WRITE_PROTECT_ERROR "Error de protección contra escritura" - #define ERR_WRITE_FAULT "Fallo al escribir" - #define ERR_LOCK_VIOLATION "Violación del bloqueo" - #define ERR_GEN_FAILURE "Fallo general" - #define ERR_UNCERTAIN_MEDIA "Medio incierto" - #define ERR_PROT_VIOLATION "Violación de la protección" - #define ERR_BROKEN_PIPE "Tubería rota" - -#else - #error Please define PHYSFS_LANG. -#endif - -/* end LANG section. */ +#define DIR_ARCHIVE_DESCRIPTION "Non-archive, direct filesystem I/O" +#define GRP_ARCHIVE_DESCRIPTION "Build engine Groupfile format" +#define HOG_ARCHIVE_DESCRIPTION "Descent I/II HOG file format" +#define MVL_ARCHIVE_DESCRIPTION "Descent II Movielib format" +#define QPAK_ARCHIVE_DESCRIPTION "Quake I/II format" +#define ZIP_ARCHIVE_DESCRIPTION "PkZip/WinZip/Info-Zip compatible" +#define WAD_ARCHIVE_DESCRIPTION "DOOM engine format" +#define LZMA_ARCHIVE_DESCRIPTION "LZMA (7zip) format" /* !!! FIXME: find something better than "dvoid" and "fvoid" ... */ @@ -739,7 +138,7 @@ typedef struct * (forWriting) is non-zero if this is to be used for * the write directory, and zero if this is to be used for an * element of the search path. - * Returns NULL on failure, and calls __PHYSFS_setError(). + * Returns NULL on failure. We ignore any error code you set here. * Returns non-NULL on success. The pointer returned will be * passed as the "opaque" parameter for later calls. */ @@ -848,7 +247,7 @@ typedef struct * * Calling this with a NULL argument is a safe no-op. */ -void __PHYSFS_setError(const char *err); +void __PHYSFS_setError(const PHYSFS_ErrorCode err); /* This byteorder stuff was lifted from SDL. http://www.libsdl.org/ */ @@ -893,16 +292,21 @@ void __PHYSFS_sort(void *entries, PHYSFS_uint32 max, int (*cmpfn)(void *, PHYSFS_uint32, PHYSFS_uint32), void (*swapfn)(void *, PHYSFS_uint32, PHYSFS_uint32)); +/* + * This isn't a formal error code, it's just for BAIL_MACRO. + * It means: there was an error, but someone else already set it for us. + */ +#define ERRPASS PHYSFS_ERR_OK /* These get used all over for lessening code clutter. */ -#define BAIL_MACRO(e, r) do { __PHYSFS_setError(e); return r; } while (0) -#define BAIL_IF_MACRO(c, e, r) do { if (c) { __PHYSFS_setError(e); return r; } } while (0) -#define BAIL_MACRO_MUTEX(e, m, r) do { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } while (0) -#define BAIL_IF_MACRO_MUTEX(c, e, m, r) do { if (c) { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } } while (0) -#define GOTO_MACRO(e, g) do { __PHYSFS_setError(e); goto g; } while (0) -#define GOTO_IF_MACRO(c, e, g) do { if (c) { __PHYSFS_setError(e); goto g; } } while (0) -#define GOTO_MACRO_MUTEX(e, m, g) do { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } while (0) -#define GOTO_IF_MACRO_MUTEX(c, e, m, g) do { if (c) { __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } } while (0) +#define BAIL_MACRO(e, r) do { if (e) __PHYSFS_setError(e); return r; } while (0) +#define BAIL_IF_MACRO(c, e, r) do { if (c) { if (e) __PHYSFS_setError(e); return r; } } while (0) +#define BAIL_MACRO_MUTEX(e, m, r) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } while (0) +#define BAIL_IF_MACRO_MUTEX(c, e, m, r) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); return r; } } while (0) +#define GOTO_MACRO(e, g) do { if (e) __PHYSFS_setError(e); goto g; } while (0) +#define GOTO_IF_MACRO(c, e, g) do { if (c) { if (e) __PHYSFS_setError(e); goto g; } } while (0) +#define GOTO_MACRO_MUTEX(e, m, g) do { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } while (0) +#define GOTO_IF_MACRO_MUTEX(c, e, m, g) do { if (c) { if (e) __PHYSFS_setError(e); __PHYSFS_platformReleaseMutex(m); goto g; } } while (0) #define __PHYSFS_ARRAYLEN(x) ( (sizeof (x)) / (sizeof (x[0])) ) diff --git a/src/platform_beos.cpp b/src/platform_beos.cpp index b3528130..c9a93635 100644 --- a/src/platform_beos.cpp +++ b/src/platform_beos.cpp @@ -40,7 +40,6 @@ #include "physfs_internal.h" - int __PHYSFS_platformInit(void) { return 1; /* always succeed. */ @@ -178,7 +177,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) const char *str = path.Path(); assert(str != NULL); char *retval = (char *) allocator.Malloc(strlen(str) + 1); - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); strcpy(retval, str); return retval; } /* __PHYSFS_platformCalcBaseDir */ diff --git a/src/platform_macosx.c b/src/platform_macosx.c index ff818c26..2cb72b85 100644 --- a/src/platform_macosx.c +++ b/src/platform_macosx.c @@ -31,8 +31,8 @@ static CFAllocatorRef cfallocator = NULL; CFStringRef cfallocDesc(const void *info) { - return(CFStringCreateWithCString(cfallocator, "PhysicsFS", - kCFStringEncodingASCII)); + return CFStringCreateWithCString(cfallocator, "PhysicsFS", + kCFStringEncodingASCII); } /* cfallocDesc */ @@ -67,7 +67,7 @@ int __PHYSFS_platformInit(void) ctx.reallocate = cfallocRealloc; ctx.deallocate = cfallocFree; cfallocator = CFAllocatorCreate(kCFAllocatorUseContext, &ctx); - BAIL_IF_MACRO(cfallocator == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!cfallocator, PHYSFS_ERR_OUT_OF_MEMORY, 0); return 1; /* success. */ } /* __PHYSFS_platformInit */ @@ -171,7 +171,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) int i, mounts; if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS) - BAIL_MACRO(ERR_OS_ERROR, ) /*return void*/; + BAIL_MACRO(PHYSFS_ERR_OS_ERROR, ) /*return void*/; mounts = getmntinfo(&mntbufp, MNT_WAIT); /* NOT THREAD SAFE! */ for (i = 0; i < mounts; i++) @@ -193,7 +193,7 @@ static char *convertCFString(CFStringRef cfstr) CFIndex len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr), kCFStringEncodingUTF8) + 1; char *retval = (char *) allocator.Malloc(len); - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); if (CFStringGetCString(cfstr, retval, len, kCFStringEncodingUTF8)) { @@ -210,7 +210,7 @@ static char *convertCFString(CFStringRef cfstr) else /* probably shouldn't fail, but just in case... */ { allocator.Free(retval); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* else */ return retval; @@ -230,15 +230,16 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) char *cstr = NULL; int rc = 0; - BAIL_IF_MACRO(GetProcessBundleLocation(&psn, &fsref) != noErr, NULL, NULL); + if (GetProcessBundleLocation(&psn, &fsref) != noErr) + BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL); cfurl = CFURLCreateFromFSRef(cfallocator, &fsref); - BAIL_IF_MACRO(cfurl == NULL, NULL, NULL); + BAIL_IF_MACRO(cfurl == NULL, PHYSFS_ERR_OS_ERROR, NULL); cfstr = CFURLCopyFileSystemPath(cfurl, kCFURLPOSIXPathStyle); CFRelease(cfurl); - BAIL_IF_MACRO(cfstr == NULL, NULL, NULL); + BAIL_IF_MACRO(!cfstr, PHYSFS_ERR_OUT_OF_MEMORY, NULL); cfmutstr = CFStringCreateMutableCopy(cfallocator, 0, cfstr); CFRelease(cfstr); - BAIL_IF_MACRO(cfmutstr == NULL, NULL, NULL); + BAIL_IF_MACRO(!cfmutstr, PHYSFS_ERR_OUT_OF_MEMORY, NULL); /* we have to decide if we got a binary's path, or the .app dir... */ cstr = convertCFString(cfmutstr); @@ -315,14 +316,16 @@ static void macosxAllocatorDeinit(void) static void *macosxAllocatorMalloc(PHYSFS_uint64 s) { - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); + if (!__PHYSFS_ui64FitsAddressSpace(s)) + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); return CFAllocatorAllocate(cfallocdef, (CFIndex) s, 0); } /* macosxAllocatorMalloc */ static void *macosxAllocatorRealloc(void *ptr, PHYSFS_uint64 s) { - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(s), ERR_OUT_OF_MEMORY, NULL); + if (!__PHYSFS_ui64FitsAddressSpace(s)) + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); return CFAllocatorReallocate(cfallocdef, ptr, (CFIndex) s, 0); } /* macosxAllocatorRealloc */ diff --git a/src/platform_posix.c b/src/platform_posix.c index e82d6536..f2cfe444 100644 --- a/src/platform_posix.c +++ b/src/platform_posix.c @@ -6,6 +6,8 @@ * This file written by Ryan C. Gordon. */ +/* !!! FIXME: check for EINTR? */ + #define __PHYSICSFS_INTERNAL__ #include "physfs_platforms.h" @@ -26,6 +28,40 @@ #include "physfs_internal.h" + +static PHYSFS_ErrorCode errcodeFromErrnoError(const int err) +{ + switch (err) + { + case 0: return PHYSFS_ERR_OK; + case EACCES: return PHYSFS_ERR_PERMISSION; + case EPERM: return PHYSFS_ERR_PERMISSION; + case EDQUOT: return PHYSFS_ERR_NO_SPACE; + case EIO: return PHYSFS_ERR_IO; + case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP; + case EMLINK: return PHYSFS_ERR_NO_SPACE; + case ENAMETOOLONG: return PHYSFS_ERR_BAD_FILENAME; + case ENOENT: return PHYSFS_ERR_NO_SUCH_PATH; + case ENOSPC: return PHYSFS_ERR_NO_SPACE; + case ENOTDIR: return PHYSFS_ERR_NO_SUCH_PATH; + case EISDIR: return PHYSFS_ERR_NOT_A_FILE; + case EROFS: return PHYSFS_ERR_READ_ONLY; + case ETXTBSY: return PHYSFS_ERR_BUSY; + case EBUSY: return PHYSFS_ERR_BUSY; + case ENOMEM: return PHYSFS_ERR_OUT_OF_MEMORY; + case ENOTEMPTY: return PHYSFS_ERR_DIR_NOT_EMPTY; + default: return PHYSFS_ERR_OS_ERROR; + } /* switch */ +} /* errcodeFromErrnoError */ + + +static inline PHYSFS_ErrorCode errcodeFromErrno(void) +{ + return errcodeFromErrnoError(errno); +} /* errcodeFromErrno */ + + + char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname) { const char *envr = getenv(varname); @@ -34,8 +70,8 @@ char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname) if (envr != NULL) { retval = (char *) allocator.Malloc(strlen(envr) + 1); - if (retval != NULL) - strcpy(retval, envr); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); + strcpy(retval, envr); } /* if */ return retval; @@ -187,10 +223,8 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, int __PHYSFS_platformMkDir(const char *path) { - int rc; - errno = 0; - rc = mkdir(path, S_IRWXU); - BAIL_IF_MACRO(rc == -1, strerror(errno), 0); + const int rc = mkdir(path, S_IRWXU); + BAIL_IF_MACRO(rc == -1, errcodeFromErrno(), 0); return 1; } /* __PHYSFS_platformMkDir */ @@ -206,22 +240,23 @@ static void *doOpen(const char *filename, int mode) mode &= ~O_APPEND; fd = open(filename, mode, S_IRUSR | S_IWUSR); - BAIL_IF_MACRO(fd < 0, strerror(errno), NULL); + BAIL_IF_MACRO(fd < 0, errcodeFromErrno(), NULL); if (appending) { if (lseek(fd, 0, SEEK_END) < 0) { + const int err = errno; close(fd); - BAIL_MACRO(strerror(errno), NULL); + BAIL_MACRO(errcodeFromErrnoError(err), NULL); } /* if */ } /* if */ retval = (int *) allocator.Malloc(sizeof (int)); - if (retval == NULL) + if (!retval) { close(fd); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* if */ *retval = fd; @@ -253,10 +288,11 @@ PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, const int fd = *((int *) opaque); ssize_t rc = 0; - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); rc = read(fd, buffer, (size_t) len); - BAIL_IF_MACRO(rc == -1, strerror(errno), (PHYSFS_sint64) rc); + BAIL_IF_MACRO(rc == -1, errcodeFromErrno(), -1); assert(rc >= 0); assert(rc <= len); return (PHYSFS_sint64) rc; @@ -269,10 +305,11 @@ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, const int fd = *((int *) opaque); ssize_t rc = 0; - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); rc = write(fd, (void *) buffer, (size_t) len); - BAIL_IF_MACRO(rc == -1, strerror(errno), rc); + BAIL_IF_MACRO(rc == -1, errcodeFromErrno(), rc); assert(rc >= 0); assert(rc <= len); return (PHYSFS_sint64) rc; @@ -282,7 +319,8 @@ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) { const int fd = *((int *) opaque); - BAIL_IF_MACRO(lseek(fd, (off_t) pos, SEEK_SET) == -1, strerror(errno), 0); + const int rc = lseek(fd, (off_t) pos, SEEK_SET); + BAIL_IF_MACRO(rc == -1, errcodeFromErrno(), 0); return 1; } /* __PHYSFS_platformSeek */ @@ -292,7 +330,7 @@ PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) const int fd = *((int *) opaque); PHYSFS_sint64 retval; retval = (PHYSFS_sint64) lseek(fd, 0, SEEK_CUR); - BAIL_IF_MACRO(retval == -1, strerror(errno), -1); + BAIL_IF_MACRO(retval == -1, errcodeFromErrno(), -1); return retval; } /* __PHYSFS_platformTell */ @@ -301,7 +339,7 @@ PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) { const int fd = *((int *) opaque); struct stat statbuf; - BAIL_IF_MACRO(fstat(fd, &statbuf) == -1, strerror(errno), -1); + BAIL_IF_MACRO(fstat(fd, &statbuf) == -1, errcodeFromErrno(), -1); return ((PHYSFS_sint64) statbuf.st_size); } /* __PHYSFS_platformFileLength */ @@ -309,7 +347,7 @@ PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) int __PHYSFS_platformFlush(void *opaque) { const int fd = *((int *) opaque); - BAIL_IF_MACRO(fsync(fd) == -1, strerror(errno), 0); + BAIL_IF_MACRO(fsync(fd) == -1, errcodeFromErrno(), 0); return 1; } /* __PHYSFS_platformFlush */ @@ -324,7 +362,7 @@ void __PHYSFS_platformClose(void *opaque) int __PHYSFS_platformDelete(const char *path) { - BAIL_IF_MACRO(remove(path) == -1, strerror(errno), 0); + BAIL_IF_MACRO(remove(path) == -1, errcodeFromErrno(), 0); return 1; } /* __PHYSFS_platformDelete */ @@ -336,7 +374,7 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *st) if (lstat(filename, &statbuf) == -1) { *exists = (errno == ENOENT); - BAIL_MACRO(strerror(errno), 0); + BAIL_MACRO(errcodeFromErrno(), 0); } /* if */ *exists = 1; @@ -398,12 +436,12 @@ void *__PHYSFS_platformCreateMutex(void) { int rc; PthreadMutex *m = (PthreadMutex *) allocator.Malloc(sizeof (PthreadMutex)); - BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!m, PHYSFS_ERR_OUT_OF_MEMORY, NULL); rc = pthread_mutex_init(&m->mutex, NULL); if (rc != 0) { allocator.Free(m); - BAIL_MACRO(strerror(rc), NULL); + BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL); } /* if */ m->count = 0; diff --git a/src/platform_unix.c b/src/platform_unix.c index 4fea9d6d..c992537b 100644 --- a/src/platform_unix.c +++ b/src/platform_unix.c @@ -90,7 +90,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) struct mntent *ent = NULL; mounts = setmntent("/etc/mtab", "r"); - BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, /*return void*/); + BAIL_IF_MACRO(mounts == NULL, PHYSFS_ERR_IO, /*return void*/); while ( (ent = getmntent(mounts)) != NULL ) { @@ -120,7 +120,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) FILE *mounts = fopen(MNTTAB, "r"); struct mnttab ent; - BAIL_IF_MACRO(mounts == NULL, ERR_IO_ERROR, /*return void*/); + BAIL_IF_MACRO(mounts == NULL, PHYSFS_ERR_IO, /*return void*/); while (getmntent(mounts, &ent) == 0) { int add_it = 0; @@ -161,8 +161,8 @@ static char *findBinaryInPath(const char *bin, char *envr) char *start = envr; char *ptr; - BAIL_IF_MACRO(bin == NULL, ERR_INVALID_ARGUMENT, NULL); - BAIL_IF_MACRO(envr == NULL, ERR_INVALID_ARGUMENT, NULL); + assert(bin != NULL); + assert(envr != NULL); do { @@ -175,11 +175,11 @@ static char *findBinaryInPath(const char *bin, char *envr) if (size > alloc_size) { char *x = (char *) allocator.Realloc(exe, size); - if (x == NULL) + if (!x) { if (exe != NULL) allocator.Free(exe); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* if */ alloc_size = size; @@ -276,7 +276,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) { /* If there's no dirsep on argv0, then look through $PATH for it. */ envr = __PHYSFS_platformCopyEnvironmentVariable("PATH"); - BAIL_IF_MACRO(!envr, NULL, NULL); + BAIL_IF_MACRO(!envr, ERRPASS, NULL); retval = findBinaryInPath(argv0, envr); allocator.Free(envr); } /* if */ diff --git a/src/platform_windows.c b/src/platform_windows.c index 7303f8b3..f7d0013e 100644 --- a/src/platform_windows.c +++ b/src/platform_windows.c @@ -71,7 +71,7 @@ static char *unicodeToUtf8Heap(const WCHAR *w_str) void *ptr = NULL; const PHYSFS_uint64 len = (wStrLen(w_str) * 4) + 1; retval = allocator.Malloc(len); - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); PHYSFS_utf8FromUtf16((const PHYSFS_uint16 *) w_str, retval, len); ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */ if (ptr != NULL) @@ -95,46 +95,67 @@ static HWND detectCDHwnd = 0; static volatile int initialDiscDetectionComplete = 0; static volatile DWORD drivesWithMediaBitmap = 0; -/* - * Figure out what the last failing Windows API call was, and - * generate a human-readable string for the error message. - * - * The return value is a static buffer that is overwritten with - * each call to this function. - */ -static const char *winApiStrErrorByNum(const DWORD err) -{ - static char utf8buf[255]; - WCHAR msgbuf[255]; - WCHAR *ptr; - DWORD rc = FormatMessageW( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - msgbuf, __PHYSFS_ARRAYLEN(msgbuf), - NULL); - - if (rc == 0) - msgbuf[0] = '\0'; /* oh well. */ - - /* chop off newlines. */ - for (ptr = msgbuf; *ptr; ptr++) + +static PHYSFS_ErrorCode errcodeFromWinApiError(const DWORD err) +{ + /* + * win32 error codes are sort of a tricky thing; Microsoft intentionally + * doesn't list which ones a given API might trigger, there are several + * with overlapping and unclear meanings...and there's 16 thousand of + * them in Windows 7. It looks like the ones we care about are in the + * first 500, but I can't say this list is perfect; we might miss + * important values or misinterpret others. + * + * Don't treat this list as anything other than a work in progress. + */ + switch (err) { - if ((*ptr == '\n') || (*ptr == '\r')) - { - *ptr = '\0'; - break; - } /* if */ - } /* for */ + case ERROR_SUCCESS: return PHYSFS_ERR_OK; + case ERROR_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION; + case ERROR_NETWORK_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION; + case ERROR_DISK_RESOURCES_EXHAUSTED: return PHYSFS_ERR_NO_SPACE; + case ERROR_NOT_READY: return PHYSFS_ERR_IO; + case ERROR_CRC: return PHYSFS_ERR_IO; + case ERROR_SEEK: return PHYSFS_ERR_IO; + case ERROR_SECTOR_NOT_FOUND: return PHYSFS_ERR_IO; + case ERROR_NOT_DOS_DISK: return PHYSFS_ERR_IO; + case ERROR_WRITE_FAULT: return PHYSFS_ERR_IO; + case ERROR_READ_FAULT: return PHYSFS_ERR_IO; + case ERROR_DEV_NOT_EXIST: return PHYSFS_ERR_IO; + case ERROR_DATA_CHECKSUM_ERROR: return PHYSFS_ERR_IO; + /* !!! FIXME: ?? case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP; */ + case ERROR_BUFFER_OVERFLOW: return PHYSFS_ERR_BAD_FILENAME; + case ERROR_INVALID_NAME: return PHYSFS_ERR_BAD_FILENAME; + case ERROR_BAD_PATHNAME: return PHYSFS_ERR_BAD_FILENAME; + case ERROR_DIRECTORY: return PHYSFS_ERR_BAD_FILENAME; + case ERROR_FILE_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH; + case ERROR_PATH_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH; + case ERROR_DELETE_PENDING: return PHYSFS_ERR_NO_SUCH_PATH; + case ERROR_INVALID_DRIVE: return PHYSFS_ERR_NO_SUCH_PATH; + case ERROR_HANDLE_DISK_FULL: return PHYSFS_ERR_NO_SPACE; + case ERROR_DISK_FULL: return PHYSFS_ERR_NO_SPACE; + /* !!! FIXME: ?? case ENOTDIR: return PHYSFS_ERR_NO_SUCH_PATH; */ + /* !!! FIXME: ?? case EISDIR: return PHYSFS_ERR_NOT_A_FILE; */ + case ERROR_WRITE_PROTECT: return PHYSFS_ERR_READ_ONLY; + case ERROR_LOCK_VIOLATION: return PHYSFS_ERR_BUSY; + case ERROR_SHARING_VIOLATION: return PHYSFS_ERR_BUSY; + case ERROR_CURRENT_DIRECTORY: return PHYSFS_ERR_BUSY; + case ERROR_DRIVE_LOCKED: return PHYSFS_ERR_BUSY; + case ERROR_PATH_BUSY: return PHYSFS_ERR_BUSY; + case ERROR_BUSY: return PHYSFS_ERR_BUSY; + case ERROR_NOT_ENOUGH_MEMORY: return PHYSFS_ERR_OUT_OF_MEMORY; + case ERROR_OUTOFMEMORY: return PHYSFS_ERR_OUT_OF_MEMORY; + case ERROR_DIR_NOT_EMPTY: return PHYSFS_ERR_DIR_NOT_EMPTY; + default: return PHYSFS_ERR_OS_ERROR; + } /* switch */ +} /* errcodeFromWinApiError */ + +static inline PHYSFS_ErrorCode errcodeFromWinApi(void) +{ + return errcodeFromWinApiError(GetLastError()); +} /* errcodeFromWinApi */ - /* may truncate, but oh well. */ - PHYSFS_utf8FromUcs2((PHYSFS_uint16 *) msgbuf, utf8buf, sizeof (utf8buf)); - return ((const char *) utf8buf); -} /* winApiStrErrorByNum */ -static inline const char *winApiStrError(void) -{ - return winApiStrErrorByNum(GetLastError()); -} /* winApiStrError */ /* * On success, module-scope variable (userDir) will have a pointer to @@ -154,10 +175,10 @@ static int determineUserDir(void) pGetDir = (fnGetUserProfDirW) GetProcAddress(libUserEnv, "GetUserProfileDirectoryW"); - BAIL_IF_MACRO(pGetDir == NULL, winApiStrError(), 0); + BAIL_IF_MACRO(pGetDir == NULL, errcodeFromWinApi(), 0); if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken)) - BAIL_MACRO(winApiStrError(), 0); + BAIL_MACRO(errcodeFromWinApi(), 0); else { DWORD psize = 0; @@ -376,7 +397,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) if ( (ptr = allocator.Realloc(modpath, buflen*sizeof(WCHAR))) == NULL ) { allocator.Free(modpath); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* if */ modpath = (LPWSTR) ptr; @@ -384,7 +405,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) if (rc == 0) { allocator.Free(modpath); - BAIL_MACRO(winApiStrError(), NULL); + BAIL_MACRO(errcodeFromWinApi(), NULL); } /* if */ if (rc < buflen) @@ -428,9 +449,9 @@ char *__PHYSFS_platformGetUserName(void) if (GetUserNameW(NULL, &bufsize) == 0) /* This SHOULD fail. */ { LPWSTR wbuf = (LPWSTR) __PHYSFS_smallAlloc(bufsize * sizeof (WCHAR)); - BAIL_IF_MACRO(wbuf == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!wbuf, PHYSFS_ERR_OUT_OF_MEMORY, NULL); if (GetUserNameW(wbuf, &bufsize) == 0) /* ?! */ - __PHYSFS_setError(winApiStrError()); + __PHYSFS_setError(errcodeFromWinApi()); else retval = unicodeToUtf8Heap(wbuf); __PHYSFS_smallFree(wbuf); @@ -443,7 +464,7 @@ char *__PHYSFS_platformGetUserName(void) char *__PHYSFS_platformGetUserDir(void) { char *retval = (char *) allocator.Malloc(strlen(userDir) + 1); - BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); strcpy(retval, userDir); /* calculated at init time. */ return retval; } /* __PHYSFS_platformGetUserDir */ @@ -493,7 +514,7 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname, strcat(searchPath, "*"); UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath); - if (wSearchPath == NULL) + if (!wSearchPath) return; /* oh well. */ dir = FindFirstFileW(wSearchPath, &entw); @@ -536,7 +557,7 @@ int __PHYSFS_platformMkDir(const char *path) UTF8_TO_UNICODE_STACK_MACRO(wpath, path); rc = CreateDirectoryW(wpath, NULL); __PHYSFS_smallFree(wpath); - BAIL_IF_MACRO(rc == 0, winApiStrError(), 0); + BAIL_IF_MACRO(rc == 0, errcodeFromWinApi(), 0); return 1; } /* __PHYSFS_platformMkDir */ @@ -544,17 +565,17 @@ int __PHYSFS_platformMkDir(const char *path) int __PHYSFS_platformInit(void) { libUserEnv = LoadLibraryA("userenv.dll"); - BAIL_IF_MACRO(libUserEnv == NULL, winApiStrError(), 0); + BAIL_IF_MACRO(libUserEnv == NULL, errcodeFromWinApi(), 0); /* !!! FIXME: why do we precalculate this? */ - BAIL_IF_MACRO(!determineUserDir(), NULL, 0); + BAIL_IF_MACRO(!determineUserDir(), ERRPASS, 0); return 1; /* It's all good */ } /* __PHYSFS_platformInit */ int __PHYSFS_platformDeinit(void) { - if (detectCDThreadHandle != NULL) + if (detectCDThreadHandle) { if (detectCDHwnd) PostMessageW(detectCDHwnd, WM_QUIT, 0, 0); @@ -580,18 +601,18 @@ static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly) WCHAR *wfname; UTF8_TO_UNICODE_STACK_MACRO(wfname, fname); - BAIL_IF_MACRO(wfname == NULL, ERR_OUT_OF_MEMORY, NULL); + BAIL_IF_MACRO(!wfname, PHYSFS_ERR_OUT_OF_MEMORY, NULL); fileh = CreateFileW(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL); __PHYSFS_smallFree(wfname); - BAIL_IF_MACRO(fileh == INVALID_HANDLE_VALUE,winApiStrError(), NULL); + BAIL_IF_MACRO(fileh == INVALID_HANDLE_VALUE,errcodeFromWinApi(), NULL); retval = (WinApiFile *) allocator.Malloc(sizeof (WinApiFile)); - if (retval == NULL) + if (!retval) { CloseHandle(fileh); - BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); + BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); } /* if */ retval->readonly = rdonly; @@ -621,7 +642,7 @@ void *__PHYSFS_platformOpenAppend(const char *filename) DWORD rc = SetFilePointer(h, 0, NULL, FILE_END); if (rc == PHYSFS_INVALID_SET_FILE_POINTER) { - const char *err = winApiStrError(); + const PHYSFS_ErrorCode err = errcodeFromWinApi(); CloseHandle(h); allocator.Free(retval); BAIL_MACRO(err, NULL); @@ -638,10 +659,11 @@ PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len) HANDLE Handle = ((WinApiFile *) opaque)->handle; DWORD CountOfBytesRead = 0; - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); + else if(!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, NULL)) + BAIL_MACRO(errcodeFromWinApi(), -1); - if(!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, NULL)) - BAIL_MACRO(winApiStrError(), -1); return (PHYSFS_sint64) CountOfBytesRead; } /* __PHYSFS_platformRead */ @@ -653,10 +675,11 @@ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, HANDLE Handle = ((WinApiFile *) opaque)->handle; DWORD CountOfBytesWritten = 0; - BAIL_IF_MACRO(!__PHYSFS_ui64FitsAddressSpace(len),ERR_INVALID_ARGUMENT,-1); + if (!__PHYSFS_ui64FitsAddressSpace(len)) + BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); + else if(!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, NULL)) + BAIL_MACRO(errcodeFromWinApi(), -1); - if(!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, NULL)) - BAIL_MACRO(winApiStrError(), -1); return (PHYSFS_sint64) CountOfBytesWritten; } /* __PHYSFS_platformWrite */ @@ -692,7 +715,7 @@ int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) if ( (rc == PHYSFS_INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR) ) { - BAIL_MACRO(winApiStrError(), 0); + BAIL_MACRO(errcodeFromWinApi(), 0); } /* if */ return 1; /* No error occured */ @@ -711,7 +734,7 @@ PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) if ( (LowPos == PHYSFS_INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR) ) { - BAIL_MACRO(winApiStrError(), -1); + BAIL_MACRO(errcodeFromWinApi(), -1); } /* if */ else { @@ -735,7 +758,7 @@ PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) if ( (SizeLow == PHYSFS_INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR) ) { - BAIL_MACRO(winApiStrError(), -1); + BAIL_MACRO(errcodeFromWinApi(), -1); } /* if */ else { @@ -752,7 +775,7 @@ int __PHYSFS_platformFlush(void *opaque) { WinApiFile *fh = ((WinApiFile *) opaque); if (!fh->readonly) - BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), winApiStrError(), 0); + BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), errcodeFromWinApi(), 0); return 1; } /* __PHYSFS_platformFlush */ @@ -770,7 +793,7 @@ static int doPlatformDelete(LPWSTR wpath) { const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY); const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath); - BAIL_IF_MACRO(!rc, winApiStrError(), 0); + BAIL_IF_MACRO(!rc, errcodeFromWinApi(), 0); return 1; /* if you made it here, it worked. */ } /* doPlatformDelete */ @@ -780,7 +803,7 @@ int __PHYSFS_platformDelete(const char *path) int retval = 0; LPWSTR wpath = NULL; UTF8_TO_UNICODE_STACK_MACRO(wpath, path); - BAIL_IF_MACRO(wpath == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!wpath, PHYSFS_ERR_OUT_OF_MEMORY, 0); retval = doPlatformDelete(wpath); __PHYSFS_smallFree(wpath); return retval; @@ -826,11 +849,11 @@ static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft) struct tm tm; BOOL rc; - BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), winApiStrError(), -1); + BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), errcodeFromWinApi(), -1); tzid = GetTimeZoneInformation(&tzi); - BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, winApiStrError(), -1); + BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, errcodeFromWinApi(), -1); rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz); - BAIL_IF_MACRO(!rc, winApiStrError(), -1); + BAIL_IF_MACRO(!rc, errcodeFromWinApi(), -1); /* Convert to a format that mktime() can grok... */ tm.tm_sec = st_localtz.wSecond; @@ -845,7 +868,7 @@ static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft) /* Convert to a format PhysicsFS can grok... */ retval = (PHYSFS_sint64) mktime(&tm); - BAIL_IF_MACRO(retval == -1, strerror(errno), -1); + BAIL_IF_MACRO(retval == -1, PHYSFS_ERR_OS_ERROR, -1); return retval; } /* FileTimeToPhysfsTime */ @@ -857,12 +880,12 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat) BOOL rc = 0; UTF8_TO_UNICODE_STACK_MACRO(wstr, filename); - BAIL_IF_MACRO(wstr == NULL, ERR_OUT_OF_MEMORY, 0); + BAIL_IF_MACRO(!wstr, PHYSFS_ERR_OUT_OF_MEMORY, 0); rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat); err = (!rc) ? GetLastError() : 0; *exists = ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND)); __PHYSFS_smallFree(wstr); - BAIL_IF_MACRO(!rc, winApiStrErrorByNum(err), 0); + BAIL_IF_MACRO(!rc, errcodeFromWinApiError(err), 0); stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime); stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);