From: Michael Adam Date: Wed, 13 Feb 2013 15:51:54 +0000 (+0100) Subject: lib/util/time: strip a potential trailing newline in the asctime case. X-Git-Tag: tevent-0.9.18~199 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=762dd3cf29788a9f8ab66fd96ad2b9cc20f621f3;p=thirdparty%2Fsamba.git lib/util/time: strip a potential trailing newline in the asctime case. 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 Reviewed-by: Stefan Metzmacher --- diff --git a/lib/util/time.c b/lib/util/time.c index d5a429af940..56b2ec50dec 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -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;