lib/util: Use snprintf() instead of strftime() in timeval_str_buf()
authorMartin Schwenke <martin@meltin.net>
Wed, 8 Oct 2014 04:52:37 +0000 (15:52 +1100)
committerVolker Lendecke <vl@samba.org>
Mon, 13 Oct 2014 08:05:05 +0000 (10:05 +0200)
This removes conditional code and ensures that the output is always as
expected.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
lib/util/time_basic.c
lib/util/time_basic.h

index b6e73171e4ae79b7e78727bc59a29ef86a23cace..13d0bfdb5e6500ab87ea464ca81d5a4b532a41a5 100644 (file)
@@ -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);
index 58bc02de3caa9dd98d0422f6e527ab4d1185a9ba..b04dead10099dcbb84fc45d9b529d30981cf6ec4 100644 (file)
@@ -35,7 +35,7 @@ struct timeval_buf { char buf[128]; };
  Put a date and time into dst->buf, return it dst->buf
  (optionally with microseconds)
 
- format is %Y/%m/%d %H:%M:%S if strftime is available
+ format is %Y/%m/%d %H:%M:%S
 **/
 
 char *timeval_str_buf(const struct timeval *tp, bool hires,