wrong timestamp in log files
Youzhong Yang
Youzhong.Yang at mathworks.com
Thu Dec 11 10:48:36 MST 2014
Hi Martin,
I saw the timestamp in log files having the wrong month. Looking at the commit, shouldn't the tm->tm_mon be tm->tm_mon + 1?
Thanks,
-Youzhong Yang
========================================================================
commit 1c2ae58509a19fb4590f4c71277c0f0c0a27f2fd
Author: Martin Schwenke <martin at meltin.net>
Date: Wed Oct 8 15:52:37 2014 +1100
lib/util: Use snprintf() instead of strftime() in timeval_str_buf()
This removes conditional code and ensures that the output is always as
expected.
Signed-off-by: Martin Schwenke <martin at meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Volker Lendecke <vl at samba.org>
diff --git a/lib/util/time_basic.c b/lib/util/time_basic.c
index b6e7317..13d0bfd 100644
--- a/lib/util/time_basic.c
+++ b/lib/util/time_basic.c
@@ -62,15 +62,11 @@ char *timeval_str_buf(const struct timeval *tp, bool hires,
return dst->buf;
}
-#ifdef HAVE_STRFTIME
- len = strftime(dst->buf, sizeof(dst->buf), "%Y/%m/%d %H:%M:%S", tm);
-#else
- {
- const char *asct = asctime(tm);
- len = strlcpy(dst->buf, sizeof(dst->buf),
- asct ? asct : "unknown");
- }
-#endif
+ len = snprintf(dst->buf, sizeof(dst->buf),
+ "%04d/%02d/%02d %02d:%02d:%02d",
+ 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+
if (hires && (len < sizeof(dst->buf))) {
snprintf(dst->buf + len, sizeof(dst->buf) - len,
".%06ld", (long)tp->tv_usec);
More information about the samba-technical
mailing list