From 9bcd3c1023cc57477990c5c3e9dacf3b7b67be25 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Sat, 25 May 2002 11:13:09 +0000 Subject: [PATCH] Added getlastmodtime command. --- test/test_physfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_physfs.c b/test/test_physfs.c index 5b2b2a14..66d21aca 100644 --- a/test/test_physfs.c +++ b/test/test_physfs.c @@ -25,6 +25,8 @@ #include #endif +#include + #include "physfs.h" #define TEST_VERSION_MAJOR 0 @@ -557,6 +559,31 @@ static int cmd_write(char *args) } /* 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 @@ static const command_info commands[] = { "filelength", cmd_filelength, 1, "" }, { "append", cmd_append, 1, "" }, { "write", cmd_write, 1, "" }, + { "getlastmodtime", cmd_getlastmodtime, 1, "" }, { NULL, NULL, -1, NULL } }; + static void output_usage(const char *intro, const command_info *cmdinfo) { if (cmdinfo->argcount == 0)