From b69dfedaf005c5203d817588adadd4ca06c9753a Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 21 Aug 2010 17:34:00 -0400 Subject: [PATCH] Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now. --- src/physfs.c | 42 ++++-------------------------------------- src/physfs.h | 35 ++++++++++++++++++++--------------- test/test_physfs.c | 8 ++++---- 3 files changed, 28 insertions(+), 57 deletions(-) diff --git a/src/physfs.c b/src/physfs.c index b131a1fa..94617604 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -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 */ diff --git a/src/physfs.h b/src/physfs.h index c3e147ab..e111e3ea 100644 --- a/src/physfs.h +++ b/src/physfs.h @@ -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... */ @@ -2529,12 +2533,13 @@ 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 @@ -2542,7 +2547,7 @@ typedef enum 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? */ @@ -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 */ diff --git a/test/test_physfs.c b/test/test_physfs.c index 181ffd77..a3c75e13 100644 --- a/test/test_physfs.c +++ b/test/test_physfs.c @@ -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;