Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.

This commit is contained in:
Ryan C. Gordon 2010-08-21 19:10:42 -04:00
parent b69dfedaf0
commit f7a8d9292c
15 changed files with 38 additions and 29 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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