Skip to content
Permalink
Browse files
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
  • Loading branch information
icculus committed Aug 21, 2010
1 parent b69dfed commit f7a8d9292cdc3adc6b0842b7fbac60ebcf338602
Showing with 38 additions and 29 deletions.
  1. +1 −1 src/archiver_grp.c
  2. +1 −1 src/archiver_hog.c
  3. +1 −1 src/archiver_iso9660.c
  4. +1 −1 src/archiver_lzma.c
  5. +1 −1 src/archiver_mvl.c
  6. +1 −1 src/archiver_qpak.c
  7. +1 −1 src/archiver_wad.c
  8. +1 −1 src/archiver_zip.c
  9. +15 −5 src/physfs.c
  10. +2 −1 src/physfs.h
  11. +2 −2 src/platform_os2.c
  12. +2 −2 src/platform_pocketpc.c
  13. +3 −5 src/platform_posix.c
  14. +4 −4 src/platform_windows.c
  15. +2 −2 test/test_physfs.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 */


@@ -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 */


@@ -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 */


@@ -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 */


@@ -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 */


@@ -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 */


@@ -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 */


@@ -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 */


@@ -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,16 +2172,21 @@ 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))
{
if (*fname == '\0')
{
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);
@@ -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
*/
@@ -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 */


@@ -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 */


@@ -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 */
@@ -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 */


@@ -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;

0 comments on commit f7a8d92

Please sign in to comment.