Skip to content

Commit

Permalink
Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Aug 21, 2010
1 parent 8b0988a commit b69dfed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 57 deletions.
42 changes: 4 additions & 38 deletions src/physfs.c
Expand Up @@ -1627,45 +1627,11 @@ int PHYSFS_exists(const char *fname)
} /* 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;
char *fname;
size_t len;

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_Stat statbuf;
BAIL_IF_MACRO(PHYSFS_stat(fname, &statbuf) != 0, NULL, -1);
return statbuf.modtime;
} /* PHYSFS_getLastModTime */


Expand Down
35 changes: 20 additions & 15 deletions src/physfs.h
Expand Up @@ -1118,18 +1118,22 @@ PHYSFS_DECL int PHYSFS_isSymbolicLink(const char *fname);
* \fn PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename)
* \brief Get the last modification time of a file.
*
* The modtime is returned as a number of seconds since the epoch
* (Jan 1, 1970). The exact derivation and accuracy of this time depends on
* the particular archiver. If there is no reasonable way to obtain this
* information for a particular archiver, or there was some sort of error,
* this function returns (-1).
* The modtime is returned as a number of seconds since the Unix epoch
* (midnight, Jan 1, 1970). The exact derivation and accuracy of this time
* depends on the particular archiver. If there is no reasonable way to
* obtain this information for a particular archiver, or there was some sort
* 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.
* \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... */
Expand Down Expand Up @@ -2529,20 +2533,21 @@ typedef enum PHYSFS_FileType
* \brief Meta data for a file or directory
*
* Container for various meta data about a file in the virtual file system.
* 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
* is at least epoch. The FileSize is only valid for real files. And the
* readonly tells you whether when you open a file for writing you are writing
* to the same file as if you were opening it, given you have enough
* filesystem rights to do that.
* PHYSFS_stat() uses this structure for returning the information. The time
* data will be either the number of seconds since the Unix epoch (midnight,
* Jan 1, 1970), or -1 if there the information isn't available or applicable.
* The (filesize) field is measured in bytes.
* The (readonly) field tells you whether when you open a file for writing you
* 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_FileType
*/
typedef struct PHYSFS_Stat
{
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 accesstime; /**< like modtime, but for file access time */
PHYSFS_FileType filetype; /**< File? Directory? Symlink? */
Expand All @@ -2557,7 +2562,7 @@ 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.
* \return 0 on success, non-zero on error. // !!! FIXME: arg, that's backwards from everything else in PhysicsFS!
*
* \sa PHYSFS_Stat
*/
Expand Down
8 changes: 4 additions & 4 deletions test/test_physfs.c
Expand Up @@ -930,14 +930,14 @@ static char* modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)

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

return 1;
Expand Down

0 comments on commit b69dfed

Please sign in to comment.