X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=7a3afc688ae3636bec5705994f0846933987d6a8;hb=3665f23e5708db69ec26ff908b99926afc87b2ce;hp=d3ce694021fc36fe30e04b263406622ff0c2ad0e;hpb=7fd163f5a448c2f3a3ad1978a46ef3a84c6497b1;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index d3ce6940..7a3afc68 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -918,6 +918,23 @@ char *getDefaultUserName(int nr) return user_name[nr]; } +char *getTimestampFromEpoch(time_t epoch_seconds) +{ + struct tm *now = localtime(&epoch_seconds); + static char timestamp[20]; + + sprintf(timestamp, "%04d%02d%02d-%02d%02d%02d", + now->tm_year + 1900, now->tm_mon + 1, now->tm_mday, + now->tm_hour, now->tm_min, now->tm_sec); + + return timestamp; +} + +char *getCurrentTimestamp(void) +{ + return getTimestampFromEpoch(time(NULL)); +} + time_t getFileTimestampEpochSeconds(char *filename) { struct stat file_status; @@ -1161,6 +1178,22 @@ boolean strEqualN(char *s1, char *s2, int n) strncmp(s1, s2, n) == 0); } +boolean strEqualCase(char *s1, char *s2) +{ + return (s1 == NULL && s2 == NULL ? TRUE : + s1 == NULL && s2 != NULL ? FALSE : + s1 != NULL && s2 == NULL ? FALSE : + strcasecmp(s1, s2) == 0); +} + +boolean strEqualCaseN(char *s1, char *s2, int n) +{ + return (s1 == NULL && s2 == NULL ? TRUE : + s1 == NULL && s2 != NULL ? FALSE : + s1 != NULL && s2 == NULL ? FALSE : + strncasecmp(s1, s2, n) == 0); +} + boolean strPrefix(char *s, char *prefix) { return (s == NULL && prefix == NULL ? TRUE :