Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.

This commit is contained in:
Ryan C. Gordon 2010-08-21 17:34:00 -04:00
parent 8b0988a038
commit b69dfedaf0
3 changed files with 28 additions and 57 deletions

View File

@ -1627,45 +1627,11 @@ int PHYSFS_exists(const char *fname)
} /* PHYSFS_exists */ } /* PHYSFS_exists */
/* !!! FIXME: should this just call PHYSFS_stat() now? */ PHYSFS_sint64 PHYSFS_getLastModTime(const char *fname)
PHYSFS_sint64 PHYSFS_getLastModTime(const char *_fname)
{ {
PHYSFS_sint64 retval = -1; PHYSFS_Stat statbuf;
char *fname; BAIL_IF_MACRO(PHYSFS_stat(fname, &statbuf) != 0, NULL, -1);
size_t len; return statbuf.modtime;
BAIL_IF_MACRO(_fname == NULL, ERR_INVALID_ARGUMENT, -1);
len = strlen(_fname) + 1;
fname = (char *) __PHYSFS_smallAlloc(len);
BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, -1);
if (sanitizePlatformIndependentPath(_fname, fname))
{
if (*fname == '\0') /* eh...punt if it's the root dir. */
retval = 1; /* !!! FIXME: Maybe this should be an error? */
else
{
DirHandle *i;
int exists = 0;
__PHYSFS_platformGrabMutex(stateLock);
for (i = searchPath; ((i != NULL) && (!exists)); i = i->next)
{
char *arcfname = fname;
exists = partOfMountPoint(i, arcfname);
if (exists)
retval = 1; /* !!! FIXME: What's the right value? */
else if (verifyPath(i, &arcfname, 0))
{
retval = i->funcs->getLastModTime(i->opaque, arcfname,
&exists);
} /* else if */
} /* for */
__PHYSFS_platformReleaseMutex(stateLock);
} /* else */
} /* if */
__PHYSFS_smallFree(fname);
return retval;
} /* PHYSFS_getLastModTime */ } /* PHYSFS_getLastModTime */

View File

@ -1118,18 +1118,22 @@ PHYSFS_DECL int PHYSFS_isSymbolicLink(const char *fname);
* \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename) * \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
* \brief Get the last modification time of a file. * \brief Get the last modification time of a file.
* *
* The modtime is returned as a number of seconds since the epoch * The modtime is returned as a number of seconds since the Unix epoch
* (Jan 1, 1970). The exact derivation and accuracy of this time depends on * (midnight, Jan 1, 1970). The exact derivation and accuracy of this time
* the particular archiver. If there is no reasonable way to obtain this * depends on the particular archiver. If there is no reasonable way to
* information for a particular archiver, or there was some sort of error, * obtain this information for a particular archiver, or there was some sort
* this function returns (-1). * of error, this function returns (-1).
*
* \deprecated As of PhysicsFS 2.1, use PHYSFS_stat() instead. This
* function just wraps it anyhow.
* *
* \param filename filename to check, in platform-independent notation. * \param filename filename to check, in platform-independent notation.
* \return last modified time of the file. -1 if it can't be determined. * \return last modified time of the file. -1 if it can't be determined.
* *
* \sa PHYSFS_Stat * \sa PHYSFS_stat
*/ */
PHYSFS_DECL PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename); PHYSFS_DECL PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
PHYSFS_DEPRECATED;
/* i/o stuff... */ /* i/o stuff... */
@ -2529,12 +2533,13 @@ typedef enum PHYSFS_FileType
* \brief Meta data for a file or directory * \brief Meta data for a file or directory
* *
* Container for various meta data about a file in the virtual file system. * Container for various meta data about a file in the virtual file system.
* PHYSFS_stat() uses this structure for returning the information. The time * PHYSFS_stat() uses this structure for returning the information. The time
* data will be either a real timestamp or -1 if there is none. So every value * data will be either the number of seconds since the Unix epoch (midnight,
* is at least epoch. The FileSize is only valid for real files. And the * Jan 1, 1970), or -1 if there the information isn't available or applicable.
* readonly tells you whether when you open a file for writing you are writing * The (filesize) field is measured in bytes.
* to the same file as if you were opening it, given you have enough * The (readonly) field tells you whether when you open a file for writing you
* filesystem rights to do that. * are writing to the same file as if you were opening it, given you have
* enough filesystem rights to do that. !!! FIXME: this might change.
* *
* \sa PHYSFS_stat * \sa PHYSFS_stat
* \sa PHYSFS_FileType * \sa PHYSFS_FileType
@ -2542,7 +2547,7 @@ typedef enum PHYSFS_FileType
typedef struct PHYSFS_Stat typedef struct PHYSFS_Stat
{ {
PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */ PHYSFS_sint64 filesize; /**< size in bytes, -1 for non-files and unknown */
PHYSFS_sint64 modtime; /**< same value as PHYSFS_getLastModTime() */ PHYSFS_sint64 modtime; /**< last modification time */
PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */ PHYSFS_sint64 createtime; /**< like modtime, but for file creation time */
PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */ PHYSFS_sint64 accesstime; /**< like modtime, but for file access time */
PHYSFS_FileType filetype; /**< File? Directory? Symlink? */ PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
@ -2557,7 +2562,7 @@ typedef struct PHYSFS_Stat
* *
* \param fname filename to check, in platform-indepedent notation. * \param fname filename to check, in platform-indepedent notation.
* \param stat pointer to structure to fill in with data about (fname). * \param stat pointer to structure to fill in with data about (fname).
* \return 0 on success, non-zero on error. * \return 0 on success, non-zero on error. // !!! FIXME: arg, that's backwards from everything else in PhysicsFS!
* *
* \sa PHYSFS_Stat * \sa PHYSFS_Stat
*/ */

View File

@ -930,14 +930,14 @@ static char* modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)
static int cmd_getlastmodtime(char *args) static int cmd_getlastmodtime(char *args)
{ {
PHYSFS_sint64 rc = PHYSFS_getLastModTime(args); PHYSFS_Stat statbuf;
if (rc == -1) if (PHYSFS_stat(args, &statbuf) != 0) // !!! FIXME: backwards, api will change later.
printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError()); printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError());
else else
{ {
char modstr[64]; char modstr[64];
modTimeToStr(rc, modstr, sizeof (modstr)); modTimeToStr(statbuf.modtime, modstr, sizeof (modstr));
printf("Last modified: %s (%ld).\n", modstr, (long) rc); printf("Last modified: %s (%ld).\n", modstr, (long) statbuf.modtime);
} /* else */ } /* else */
return 1; return 1;