From 762dd3cf29788a9f8ab66fd96ad2b9cc20f621f3 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 13 Feb 2013 16:51:54 +0100 Subject: 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 --- lib/util/time.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/util') diff --git a/lib/util/time.c b/lib/util/time.c index d5a429af94..56b2ec50de 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; -- cgit