test/test_physfs.c
changeset 244 c05afa0425a4
parent 237 2abc99254366
child 323 6da51f38cfd8
--- a/test/test_physfs.c	Sat May 25 11:12:40 2002 +0000
+++ b/test/test_physfs.c	Sat May 25 11:13:09 2002 +0000
@@ -25,6 +25,8 @@
 #include <readline/history.h>
 #endif
 
+#include <time.h>
+
 #include "physfs.h"
 
 #define TEST_VERSION_MAJOR  0
@@ -557,6 +559,31 @@
 } /* cmd_write */
 
 
+static void modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)
+{
+    time_t t = (time_t) modtime;
+    char *str = ctime(&t);
+    strncpy(modstr, str, strsize);
+    modstr[strsize-1] = '\0';
+} /* modTimeToStr */
+
+
+static int cmd_getlastmodtime(char *args)
+{
+    PHYSFS_sint64 rc = PHYSFS_getLastModTime(args);
+    if (rc == -1)
+        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);
+    } /* else */
+
+    return(1);
+} /* cmd_getLastModTime */
+
+
 /* must have spaces trimmed prior to this call. */
 static int count_args(const char *str)
 {
@@ -619,9 +646,11 @@
     { "filelength",     cmd_filelength,     1, "<fileToCheck>"              },
     { "append",         cmd_append,         1, "<fileToAppend>"             },
     { "write",          cmd_write,          1, "<fileToCreateOrTrash>"      },
+    { "getlastmodtime", cmd_getlastmodtime, 1, "<fileToExamine>"            },
     { NULL,             NULL,              -1, NULL                         }
 };
 
+
 static void output_usage(const char *intro, const command_info *cmdinfo)
 {
     if (cmdinfo->argcount == 0)