test/test_physfs.c
changeset 244 c05afa0425a4
parent 237 2abc99254366
child 323 6da51f38cfd8
equal deleted inserted replaced
243:9a9f989f399b 244:c05afa0425a4
    22 #if (defined PHYSFS_HAVE_READLINE)
    22 #if (defined PHYSFS_HAVE_READLINE)
    23 #include <unistd.h>
    23 #include <unistd.h>
    24 #include <readline/readline.h>
    24 #include <readline/readline.h>
    25 #include <readline/history.h>
    25 #include <readline/history.h>
    26 #endif
    26 #endif
       
    27 
       
    28 #include <time.h>
    27 
    29 
    28 #include "physfs.h"
    30 #include "physfs.h"
    29 
    31 
    30 #define TEST_VERSION_MAJOR  0
    32 #define TEST_VERSION_MAJOR  0
    31 #define TEST_VERSION_MINOR  1
    33 #define TEST_VERSION_MINOR  1
   553         PHYSFS_close(f);
   555         PHYSFS_close(f);
   554     } /* else */
   556     } /* else */
   555 
   557 
   556     return(1);
   558     return(1);
   557 } /* cmd_write */
   559 } /* cmd_write */
       
   560 
       
   561 
       
   562 static void modTimeToStr(PHYSFS_sint64 modtime, char *modstr, size_t strsize)
       
   563 {
       
   564     time_t t = (time_t) modtime;
       
   565     char *str = ctime(&t);
       
   566     strncpy(modstr, str, strsize);
       
   567     modstr[strsize-1] = '\0';
       
   568 } /* modTimeToStr */
       
   569 
       
   570 
       
   571 static int cmd_getlastmodtime(char *args)
       
   572 {
       
   573     PHYSFS_sint64 rc = PHYSFS_getLastModTime(args);
       
   574     if (rc == -1)
       
   575         printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError());
       
   576     else
       
   577     {
       
   578         char modstr[64];
       
   579         modTimeToStr(rc, modstr, sizeof (modstr));
       
   580         printf("Last modified: %s (%ld).\n", modstr, (long) rc);
       
   581     } /* else */
       
   582 
       
   583     return(1);
       
   584 } /* cmd_getLastModTime */
   558 
   585 
   559 
   586 
   560 /* must have spaces trimmed prior to this call. */
   587 /* must have spaces trimmed prior to this call. */
   561 static int count_args(const char *str)
   588 static int count_args(const char *str)
   562 {
   589 {
   617     { "issymlink",      cmd_issymlink,      1, "<fileToCheck>"              },
   644     { "issymlink",      cmd_issymlink,      1, "<fileToCheck>"              },
   618     { "cat",            cmd_cat,            1, "<fileToCat>"                },
   645     { "cat",            cmd_cat,            1, "<fileToCat>"                },
   619     { "filelength",     cmd_filelength,     1, "<fileToCheck>"              },
   646     { "filelength",     cmd_filelength,     1, "<fileToCheck>"              },
   620     { "append",         cmd_append,         1, "<fileToAppend>"             },
   647     { "append",         cmd_append,         1, "<fileToAppend>"             },
   621     { "write",          cmd_write,          1, "<fileToCreateOrTrash>"      },
   648     { "write",          cmd_write,          1, "<fileToCreateOrTrash>"      },
       
   649     { "getlastmodtime", cmd_getlastmodtime, 1, "<fileToExamine>"            },
   622     { NULL,             NULL,              -1, NULL                         }
   650     { NULL,             NULL,              -1, NULL                         }
   623 };
   651 };
       
   652 
   624 
   653 
   625 static void output_usage(const char *intro, const command_info *cmdinfo)
   654 static void output_usage(const char *intro, const command_info *cmdinfo)
   626 {
   655 {
   627     if (cmdinfo->argcount == 0)
   656     if (cmdinfo->argcount == 0)
   628         printf("%s \"%s\" (no arguments)\n", intro, cmdinfo->cmd);
   657         printf("%s \"%s\" (no arguments)\n", intro, cmdinfo->cmd);