|
|
@@ -1239,13 +1239,9 @@ void bfg_init_time()
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
-int format_timestamp(char * const buf, const int fmt, const struct timeval * const tv)
|
|
|
+int format_tm(char * const buf, const int fmt, const struct tm * const tm, const long usecs)
|
|
|
{
|
|
|
- struct tm tm;
|
|
|
char *s = buf;
|
|
|
- time_t tt = tv->tv_sec;
|
|
|
-
|
|
|
- localtime_r(&tt, &tm);
|
|
|
|
|
|
if (fmt & BTF_BRACKETS)
|
|
|
(s++)[0] = '[';
|
|
|
@@ -1253,9 +1249,9 @@ int format_timestamp(char * const buf, const int fmt, const struct timeval * con
|
|
|
{
|
|
|
s +=
|
|
|
sprintf(s, "%d-%02d-%02d",
|
|
|
- tm.tm_year + 1900,
|
|
|
- tm.tm_mon + 1,
|
|
|
- tm.tm_mday);
|
|
|
+ tm->tm_year + 1900,
|
|
|
+ tm->tm_mon + 1,
|
|
|
+ tm->tm_mday);
|
|
|
if (fmt & BTF_TIME)
|
|
|
(s++)[0] = ' ';
|
|
|
}
|
|
|
@@ -1263,12 +1259,12 @@ int format_timestamp(char * const buf, const int fmt, const struct timeval * con
|
|
|
{
|
|
|
s +=
|
|
|
sprintf(s, "%02d:%02d:%02d",
|
|
|
- tm.tm_hour,
|
|
|
- tm.tm_min,
|
|
|
- tm.tm_sec);
|
|
|
+ tm->tm_hour,
|
|
|
+ tm->tm_min,
|
|
|
+ tm->tm_sec);
|
|
|
if (fmt & BTF_USEC)
|
|
|
s +=
|
|
|
- sprintf(s, ".%06ld", (long)tv->tv_usec);
|
|
|
+ sprintf(s, ".%06ld", usecs);
|
|
|
}
|
|
|
if (fmt & BTF_BRACKETS)
|
|
|
s +=
|
|
|
@@ -1277,6 +1273,16 @@ int format_timestamp(char * const buf, const int fmt, const struct timeval * con
|
|
|
return (s - buf);
|
|
|
}
|
|
|
|
|
|
+int format_timestamp(char * const buf, const int fmt, const struct timeval * const tv)
|
|
|
+{
|
|
|
+ struct tm tm;
|
|
|
+ time_t tt = tv->tv_sec;
|
|
|
+
|
|
|
+ localtime_r(&tt, &tm);
|
|
|
+
|
|
|
+ return format_tm(buf, fmt, &tm, tv->tv_usec);
|
|
|
+}
|
|
|
+
|
|
|
void subtime(struct timeval *a, struct timeval *b)
|
|
|
{
|
|
|
timersub(a, b, b);
|