summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2013-02-13 16:51:54 +0100
committerMichael Adam <obnox@samba.org>2013-02-19 13:58:08 +0100
commit762dd3cf29788a9f8ab66fd96ad2b9cc20f621f3 (patch)
treebb4cf8fe357c68addcbb24b65c5adc88d0fb9869
parent4d3928a8f494661764f4a3367b2f1b94772dedf9 (diff)
downloadsamba-762dd3cf29788a9f8ab66fd96ad2b9cc20f621f3.tar.gz
samba-762dd3cf29788a9f8ab66fd96ad2b9cc20f621f3.tar.bz2
samba-762dd3cf29788a9f8ab66fd96ad2b9cc20f621f3.zip
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 <obnox@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
-rw-r--r--lib/util/time.c9
1 files changed, 9 insertions, 0 deletions
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;