Use localtime_r in get_midnight_timestamp()

It's thread-safe and it's 4x faster too
This commit is contained in:
JesterHodl 2024-10-25 00:00:26 +02:00 committed by GitHub
parent 62d92d04fb
commit c4900b4afd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -231,12 +231,13 @@ int datum_logger_queue_msg(const char *func, int level, const char *format, ...)
time_t get_midnight_timestamp(void) { time_t get_midnight_timestamp(void) {
time_t now = time(NULL); time_t now = time(NULL);
struct tm *tm_now = localtime(&now); struct tm tm_now;
tm_now->tm_hour = 0; localtime_r(&now, &tm_now);
tm_now->tm_min = 0; tm_now.tm_hour = 0;
tm_now->tm_sec = 0; tm_now.tm_min = 0;
tm_now->tm_mday += 1; tm_now.tm_sec = 0;
time_t midnight = mktime(tm_now); tm_now.tm_mday += 1;
time_t midnight = mktime(&tm_now);
return midnight; return midnight;
} }