]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib/util/time: strip a potential trailing newline in the asctime case.
authorMichael Adam <obnox@samba.org>
Wed, 13 Feb 2013 15:51:54 +0000 (16:51 +0100)
committerMichael Adam <obnox@samba.org>
Tue, 19 Feb 2013 12:58:08 +0000 (13:58 +0100)
If strftime() is not available, asctime() is used, and this usually
appends a newline character to the result. This is not desired for
timestamp().

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
lib/util/time.c

index d5a429af9408af6b25cf1ec79a0ac6fe09c49324..56b2ec50dec1a9bc53891fcea65fd991a0807f97 100644 (file)
@@ -450,6 +450,15 @@ _PUBLIC_ char *timestring(TALLOC_CTX *mem_ctx, time_t t)
        TimeBuf = talloc_strdup(mem_ctx, tempTime);
 #else
        TimeBuf = talloc_strdup(mem_ctx, asctime(tm));
+       if (TimeBuf == NULL) {
+               return NULL;
+       }
+       if (TimeBuf[0] != '\0') {
+               size_t len = strlen(TimeBuf);
+               if (TimeBuf[len - 1] == '\n') {
+                       TimeBuf[len - 1] = '\0';
+               }
+       }
 #endif
 
        return TimeBuf;