Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 21 Aug 2010 17:34:00 -0400
changeset 1105 a81d0326300f
parent 1104 9d68a3fff65c
child 1106 94c3669d0311
Deprecated PHYSFS_getLastModTime()...use PHYSFS_stat() instead, now.
src/physfs.c
src/physfs.h
test/test_physfs.c
--- a/src/physfs.c	Sat Aug 21 15:07:13 2010 -0400
+++ b/src/physfs.c	Sat Aug 21 17:34:00 2010 -0400
@@ -1627,45 +1627,11 @@
 } /* 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 */
 
 
--- a/src/physfs.h	Sat Aug 21 15:07:13 2010 -0400
+++ b/src/physfs.h	Sat Aug 21 17:34:00 2010 -0400
@@ -1118,18 +1118,22 @@
  * \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 @@
  * \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 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 @@
  *
  *    \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
  */
--- a/test/test_physfs.c	Sat Aug 21 15:07:13 2010 -0400
+++ b/test/test_physfs.c	Sat Aug 21 17:34:00 2010 -0400
@@ -930,14 +930,14 @@
 
 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;