4668. [bug] Use localtime_r and gmtime_r for thread safety.
[RT #45664]
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <isc/platform.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/util.h>
|
||||
@@ -27,19 +28,22 @@
|
||||
const char *gettime(void);
|
||||
const char *test_result_totext(test_result_t);
|
||||
|
||||
/*
|
||||
* Not thread safe.
|
||||
*/
|
||||
const char *
|
||||
gettime(void) {
|
||||
static char now[512];
|
||||
time_t t;
|
||||
#if defined(ISC_PLATFORM_USETHREADS) && !defined(WIN32)
|
||||
struct tm tm;
|
||||
#endif
|
||||
|
||||
(void)time(&t);
|
||||
|
||||
strftime(now, sizeof(now) - 1,
|
||||
"%A %d %B %H:%M:%S %Y",
|
||||
localtime(&t));
|
||||
#if defined(ISC_PLATFORM_USETHREADS) && !defined(WIN32)
|
||||
strftime(now, sizeof(now) - 1, "%A %d %B %H:%M:%S %Y",
|
||||
localtime_r(&t, &tm));
|
||||
#else
|
||||
strftime(now, sizeof(now) - 1, "%A %d %B %H:%M:%S %Y", localtime(&t));
|
||||
#endif
|
||||
|
||||
return (now);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user