From f7a8d9292cdc3adc6b0842b7fbac60ebcf338602 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 21 Aug 2010 19:10:42 -0400 Subject: [PATCH] Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API. --- src/archiver_grp.c | 2 +- src/archiver_hog.c | 2 +- src/archiver_iso9660.c | 2 +- src/archiver_lzma.c | 2 +- src/archiver_mvl.c | 2 +- src/archiver_qpak.c | 2 +- src/archiver_wad.c | 2 +- src/archiver_zip.c | 2 +- src/physfs.c | 20 +++++++++++++++----- src/physfs.h | 3 ++- src/platform_os2.c | 4 ++-- src/platform_pocketpc.c | 4 ++-- src/platform_posix.c | 8 +++----- src/platform_windows.c | 8 ++++---- test/test_physfs.c | 4 ++-- 15 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/archiver_grp.c b/src/archiver_grp.c index 9f4b1c8c..0f7e2f5e 100644 --- a/src/archiver_grp.c +++ b/src/archiver_grp.c @@ -450,7 +450,7 @@ static int GRP_stat(fvoid *opaque, const char *filename, int *exists, stat->accesstime = -1; stat->readonly = 1; - return 0; + return 1; } /* GRP_stat */ diff --git a/src/archiver_hog.c b/src/archiver_hog.c index 9b700132..90fcae32 100644 --- a/src/archiver_hog.c +++ b/src/archiver_hog.c @@ -485,7 +485,7 @@ static int HOG_stat(fvoid *opaque, const char *filename, int *exists, stat->accesstime = -1; stat->readonly = 1; - return 0; + return 1; } /* HOG_stat */ diff --git a/src/archiver_iso9660.c b/src/archiver_iso9660.c index c38f21d3..695dcc88 100644 --- a/src/archiver_iso9660.c +++ b/src/archiver_iso9660.c @@ -920,7 +920,7 @@ static int ISO9660_stat(dvoid *opaque, const char *name, int *exists, stat->filetype = PHYSFS_FILETYPE_REGULAR; } /* else */ - return 0; + return 1; } /* ISO9660_stat */ diff --git a/src/archiver_lzma.c b/src/archiver_lzma.c index b93f32d9..95ec35f6 100644 --- a/src/archiver_lzma.c +++ b/src/archiver_lzma.c @@ -721,7 +721,7 @@ static int LZMA_stat(fvoid *opaque, const char *filename, int *exists, stat->readonly = 1; /* 7zips are always read only */ - return 0; + return 1; } /* LZMA_stat */ diff --git a/src/archiver_mvl.c b/src/archiver_mvl.c index a71643e6..bbdb3649 100644 --- a/src/archiver_mvl.c +++ b/src/archiver_mvl.c @@ -445,7 +445,7 @@ static int MVL_stat(fvoid *opaque, const char *filename, int *exists, stat->accesstime = 0; stat->readonly = 1; - return 0; + return 1; } /* MVL_stat */ diff --git a/src/archiver_qpak.c b/src/archiver_qpak.c index 47d0c656..cc49248b 100644 --- a/src/archiver_qpak.c +++ b/src/archiver_qpak.c @@ -608,7 +608,7 @@ static int QPAK_stat(fvoid *opaque, const char *filename, int *exists, stat->accesstime = 0; stat->readonly = 1; - return 0; + return 1; } /* QPAK_stat */ diff --git a/src/archiver_wad.c b/src/archiver_wad.c index b58b8fc6..26722514 100644 --- a/src/archiver_wad.c +++ b/src/archiver_wad.c @@ -504,7 +504,7 @@ static int WAD_stat(fvoid *opaque, const char *filename, int *exists, stat->createtime = ((WADinfo *) opaque)->last_mod_time; stat->readonly = 1; /* WADs are always readonly */ - return 0; + return 1; } /* WAD_stat */ diff --git a/src/archiver_zip.c b/src/archiver_zip.c index 675a841e..79128a04 100644 --- a/src/archiver_zip.c +++ b/src/archiver_zip.c @@ -1433,7 +1433,7 @@ static int ZIP_stat(fvoid *opaque, const char *filename, int *exists, stat->accesstime = 0; stat->readonly = 1; /* .zip files are always read only */ - return 0; + return 1; } /* ZIP_stat */ diff --git a/src/physfs.c b/src/physfs.c index 94617604..1ea8bbe3 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -1630,7 +1630,7 @@ int PHYSFS_exists(const char *fname) PHYSFS_sint64 PHYSFS_getLastModTime(const char *fname) { PHYSFS_Stat statbuf; - BAIL_IF_MACRO(PHYSFS_stat(fname, &statbuf) != 0, NULL, -1); + BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), NULL, -1); return statbuf.modtime; } /* PHYSFS_getLastModTime */ @@ -2172,8 +2172,13 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat) fname = (char *) __PHYSFS_smallAlloc(len); BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, -1); - /* !!! FIXME: what should this be set to if we fail completely? */ - memset(stat, '\0', sizeof (PHYSFS_Stat)); + /* set some sane defaults... */ + stat->filesize = -1; + stat->modtime = -1; + stat->createtime = -1; + stat->accesstime = -1; + stat->filetype = PHYSFS_FILETYPE_OTHER; + stat->readonly = 1; /* !!! FIXME */ if (sanitizePlatformIndependentPath(_fname, fname)) { @@ -2181,7 +2186,7 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat) { stat->filetype = PHYSFS_FILETYPE_DIRECTORY; stat->readonly = !writeDir; /* Writeable if we have a writeDir */ - retval = 0; + retval = 1; } /* if */ else { @@ -2193,9 +2198,14 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat) char *arcfname = fname; exists = partOfMountPoint(i, arcfname); if (exists) - retval = 1; /* !!! FIXME: What's the right value? */ + { + stat->filetype = PHYSFS_FILETYPE_DIRECTORY; + stat->readonly = 1; /* !!! FIXME */ + retval = 1; + } /* if */ else if (verifyPath(i, &arcfname, 0)) { + /* !!! FIXME: this test is wrong and should be elsewhere. */ stat->readonly = !(writeDir && (strcmp(writeDir->dirName, i->dirName) == 0)); retval = i->funcs->stat(i->opaque, arcfname, &exists, stat); diff --git a/src/physfs.h b/src/physfs.h index e111e3ea..d4b28ce7 100644 --- a/src/physfs.h +++ b/src/physfs.h @@ -2562,7 +2562,8 @@ typedef struct PHYSFS_Stat * * \param fname filename to check, in platform-indepedent notation. * \param stat pointer to structure to fill in with data about (fname). - * \return 0 on success, non-zero on error. // !!! FIXME: arg, that's backwards from everything else in PhysicsFS! + * \return non-zero on success, zero on failure. On failure, (stat)'s + * contents are undefined. * * \sa PHYSFS_Stat */ diff --git a/src/platform_os2.c b/src/platform_os2.c index 303471df..26ce473d 100644 --- a/src/platform_os2.c +++ b/src/platform_os2.c @@ -657,7 +657,7 @@ static int __PHYSFS_platformStat(const char *_fname, int *exists, *exists = 0; return 0; } /* if */ - BAIL_MACRO(get_os2_error_string(rc), -1); + BAIL_MACRO(get_os2_error_string(rc), 0); } /* if */ *exists = 1; @@ -687,7 +687,7 @@ static int __PHYSFS_platformStat(const char *_fname, int *exists, stat->readonly = ((fs.attrFile & FILE_READONLY) == FILE_READONLY); - return 0; + return 1; } /* __PHYSFS_platformStat */ diff --git a/src/platform_pocketpc.c b/src/platform_pocketpc.c index a874cb44..3c17f2f1 100644 --- a/src/platform_pocketpc.c +++ b/src/platform_pocketpc.c @@ -609,7 +609,7 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat) *exists = 0; return 0; } /* if */ - BAIL_MACRO(win32strerror, -1); + BAIL_MACRO(win32strerror, 0); } /* if */ FindClose(searchhandle); /* close handle, not needed anymore */ @@ -631,7 +631,7 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat) stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime); stat->readonly = ((winstat.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_INROM)) != 0); - return 0; + return 1; } /* __PHYSFS_platformStat */ diff --git a/src/platform_posix.c b/src/platform_posix.c index 56a6a2e6..760becc9 100644 --- a/src/platform_posix.c +++ b/src/platform_posix.c @@ -429,10 +429,8 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *st) *exists = 0; return 0; } /* if */ - else - { - BAIL_MACRO(strerror(errno), -1); - } /* else */ + + BAIL_MACRO(strerror(errno), 0); } /* if */ if (S_ISREG(statbuf.st_mode)) @@ -459,7 +457,7 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *st) /* !!! FIXME: maybe we should just report full permissions? */ st->readonly = access(filename, W_OK); - return 0; + return 1; } /* __PHYSFS_platformStat */ #endif /* PHYSFS_PLATFORM_POSIX */ diff --git a/src/platform_windows.c b/src/platform_windows.c index 4b4a6499..da575087 100644 --- a/src/platform_windows.c +++ b/src/platform_windows.c @@ -1381,7 +1381,7 @@ static int __PHYSFS_platformStatOldWay(const char *filename, int *exists, *exists = 0; return 0; } /* if */ - BAIL_MACRO(strerror(errno), -1); + BAIL_MACRO(strerror(errno), 0); } /* if */ FindClose(searchhandle); /* close handle, not needed anymore */ @@ -1403,7 +1403,7 @@ static int __PHYSFS_platformStatOldWay(const char *filename, int *exists, stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime); stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0); - return 0; + return 1; } /* __PHYSFS_platformStatOldWay */ @@ -1442,7 +1442,7 @@ static int __PHYSFS_platformStatNewWay(const char *filename, int *exists, } /* if */ else { - BAIL_MACRO(strerror(errno), -1); + BAIL_MACRO(strerror(errno), 0); } /* else */ } /* if */ @@ -1476,7 +1476,7 @@ static int __PHYSFS_platformStatNewWay(const char *filename, int *exists, stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0); - return 0; + return 1; } /* __PHYSFS_platformStatNewWay */ diff --git a/test/test_physfs.c b/test/test_physfs.c index a3c75e13..39e8a6d0 100644 --- a/test/test_physfs.c +++ b/test/test_physfs.c @@ -931,7 +931,7 @@ static char* modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize) static int cmd_getlastmodtime(char *args) { PHYSFS_Stat statbuf; - if (PHYSFS_stat(args, &statbuf) != 0) // !!! FIXME: backwards, api will change later. + if (!PHYSFS_stat(args, &statbuf)) printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError()); else { @@ -954,7 +954,7 @@ static int cmd_stat(char *args) args[strlen(args) - 1] = '\0'; } /* if */ - if(PHYSFS_stat(args, &stat)) + if(!PHYSFS_stat(args, &stat)) { printf("failed to stat. Reason [%s].\n", PHYSFS_getLastError()); return 1;