Skip to content

Commit

Permalink
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 21, 2010
1 parent b69dfed commit f7a8d92
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/archiver_grp.c
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/archiver_hog.c
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/archiver_iso9660.c
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/archiver_lzma.c
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/archiver_mvl.c
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/archiver_qpak.c
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/archiver_wad.c
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/archiver_zip.c
Expand Up @@ -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 */


Expand Down
20 changes: 15 additions & 5 deletions src/physfs.c
Expand Up @@ -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 */

Expand Down Expand Up @@ -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
{
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/physfs.h
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/platform_os2.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions src/platform_pocketpc.c
Expand Up @@ -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 */
Expand All @@ -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 */


Expand Down
8 changes: 3 additions & 5 deletions src/platform_posix.c
Expand Up @@ -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))
Expand All @@ -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 */
Expand Down
8 changes: 4 additions & 4 deletions src/platform_windows.c
Expand Up @@ -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 */
Expand All @@ -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 */


Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */


Expand Down
4 changes: 2 additions & 2 deletions test/test_physfs.c
Expand Up @@ -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
{
Expand All @@ -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;
Expand Down

0 comments on commit f7a8d92

Please sign in to comment.