util: fix printing of timestamps when time_t is longer than long
This commit is contained in:
parent
36b25cbd2b
commit
fc2892fbb0
2 changed files with 8 additions and 4 deletions
|
@ -62,10 +62,10 @@
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#if HAS_STDINT_H
|
#ifdef HAS_INTTYPES_H
|
||||||
#include <stdint.h>
|
|
||||||
#elif defined(HAS_INTTYPES_H)
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#elif HAS_STDINT_H
|
||||||
|
#include <stdint.h>
|
||||||
#else
|
#else
|
||||||
/* Tough */
|
/* Tough */
|
||||||
#endif
|
#endif
|
||||||
|
|
6
util.c
6
util.c
|
@ -210,9 +210,13 @@ UTI_TimevalToString(struct timeval *tv)
|
||||||
char *result;
|
char *result;
|
||||||
|
|
||||||
result = NEXT_BUFFER;
|
result = NEXT_BUFFER;
|
||||||
/* TODO: time_t may be wider than long, switch to int64_t before 2038 */
|
#ifdef HAVE_LONG_TIME_T
|
||||||
|
snprintf(result, BUFFER_LENGTH, "%"PRId64".%06lu",
|
||||||
|
(int64_t)tv->tv_sec, (unsigned long)tv->tv_usec);
|
||||||
|
#else
|
||||||
snprintf(result, BUFFER_LENGTH, "%ld.%06lu",
|
snprintf(result, BUFFER_LENGTH, "%ld.%06lu",
|
||||||
(long)tv->tv_sec, (unsigned long)tv->tv_usec);
|
(long)tv->tv_sec, (unsigned long)tv->tv_usec);
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue