src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/logcommon.c src/shared/queued_entry.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/queued_entry_timestamp.c
src_tests_logprint_CFLAGS = $(check_CFLAGS)
-src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime,--wrap=strdup,--wrap=strndup,--wrap=list_add
+src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime_r,--wrap=strdup,--wrap=strndup,--wrap=list_add
src_tests_logger_SOURCES = src/tests/logger.c $(dlog_logger_SOURCES)
src_tests_logger_CFLAGS = $(check_CFLAGS)
const time_t tt = ts.tv_sec;
const long int real_millisec = ts.tv_nsec / 1000000;
clock_gettime(CLOCK_MONOTONIC, &ts);
-#ifdef HAVE_LOCALTIME_R
struct tm tmBuf;
struct tm *const ptm = localtime_r(&tt, &tmBuf);
-#else
- struct tm *const ptm = localtime(&tt);
-#endif
assert(ptm); // we're in a short lived fork so asserts are fine and make things simple
int len = strftime(buf, buflen, "%m-%d %H:%M:%S", ptm);
return NULL;
char recv_real[64], recv_mono[64], sent_real[64], sent_mono[64];
-#if defined(HAVE_LOCALTIME_R)
struct tm tmBuf;
-#endif
struct tm* ptm;
time_t time_t_temp;
recv_real[0] = '\0';
else {
time_t_temp = entry->sec_recv_real;
-#if defined(HAVE_LOCALTIME_R)
ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
- ptm = localtime(&time_t_temp);
-#endif
if (!ptm)
return NULL;
strftime(recv_real, sizeof recv_real, "\"recv_real\":\"%FT%T%z\",", ptm);
sent_real[0] = '\0';
else {
time_t_temp = entry->sec_sent_real;
-#if defined(HAVE_LOCALTIME_R)
ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
- ptm = localtime(&time_t_temp);
-#endif
if (!ptm)
return NULL;
strftime(sent_real, sizeof sent_real, "\"sent_real\":\"%FT%T%z\",", ptm);
const dlogutil_entry_s *entry,
size_t *p_outLength)
{
-#if defined(HAVE_LOCALTIME_R)
struct tm tmBuf;
-#endif
struct tm* ptm;
time_t time_t_temp;
char timeBuf[32], tzBuf[16];
nsec_recv = ts.tv_nsec;
time_t_temp = sec_sent;
-#if defined(HAVE_LOCALTIME_R)
ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
- ptm = localtime(&time_t_temp);
-#endif
if (!ptm)
return NULL;
strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
time_t_temp = sec_recv;
-#if defined(HAVE_LOCALTIME_R)
ptm = localtime_r(&time_t_temp, &tmBuf);
-#else
- ptm = localtime(&time_t_temp);
-#endif
if (!ptm)
return NULL;
return count;
}
-static int fail_localtime;
-struct tm *__real_localtime(const time_t *timep);
-struct tm *__wrap_localtime(const time_t *timep)
+static int fail_localtime_r;
+struct tm *__real_localtime_r(const time_t *timep, struct tm *result);
+struct tm *__wrap_localtime_r(const time_t *timep, struct tm *result)
{
- struct tm *const ret = (fail_localtime & 1) ? NULL : __real_localtime(timep);
- fail_localtime >>= 1;
+ struct tm *const ret = (fail_localtime_r & 1) ? NULL : __real_localtime_r(timep, result);
+ fail_localtime_r >>= 1;
return ret;
}
assert(-1 == log_print_log_line(format, 0, &entry.header));
fail_alloc = false;
- fail_localtime = 1;
+ fail_localtime_r = 1;
assert(-1 == log_print_log_line(format, 0, &entry.header));
- fail_localtime = 2;
+ fail_localtime_r = 2;
assert(-1 == log_print_log_line(format, 0, &entry.header));
partial_write = -1;