diff --git a/avs/platform.h b/avs/platform.h index 51c7fa9..5919a6a 100644 --- a/avs/platform.h +++ b/avs/platform.h @@ -62,6 +62,13 @@ uint64_t timer_us(); */ double timer_us_precision(); +/** + * Return a string pointer with the current date in the format "YYYY-MM-DD" (11 bytes). + * The data is stored in a static buffer, so the return pointer is always the same, but + * its contents are not guaranteed to stay the same between calls to this function. + */ +const char* current_date_str(); + /** * Create a new lock object. */ diff --git a/avs/platform_linux.c b/avs/platform_linux.c index caa181d..b481c3c 100644 --- a/avs/platform_linux.c +++ b/avs/platform_linux.c @@ -12,7 +12,7 @@ #include // mprotect flags #include // mkdir() -/* timers */ +/* timers & time */ uint64_t timer_ms() { struct timespec ts; @@ -38,6 +38,19 @@ double timer_us_precision() { return ts.tv_sec * 1000.0 * 1000.0 + (double)ts.tv_nsec / 1000.0; } +const char* current_date_str() { + static char date_str[11]; + time_t t = time(NULL); + struct tm date = *localtime(&t); + snprintf(date_str, + 11, + "%04d-%02d-%02d", + date.tm_year + 1900, + date.tm_mon + 1, + date.tm_mday); + return date_str; +} + /* locking */ #define PTHREAD_LOCK(lock) ((pthread_mutex_t*)(lock)) diff --git a/avs/platform_win32.c b/avs/platform_win32.c index 3d919c9..ddee49a 100644 --- a/avs/platform_win32.c +++ b/avs/platform_win32.c @@ -5,7 +5,7 @@ #include #include -/* timers */ +/* timers & time */ static int64_t timer_highres_ticks_per_us = 0; @@ -36,6 +36,14 @@ double timer_us_precision() { return 1.0f / (double)timer_highres_ticks_per_us; } +const char* current_date_str() { + static char date_str[11]; + SYSTEMTIME date; + GetLocalTime(&date); + snprintf(date_str, 11, "%04d-%02d-%02d", date.wYear, date.wMonth, date.wDay); + return date_str; +} + /* locking */ #define WIN_LOCK(lock) ((CRITICAL_SECTION*)(lock))