From ea969611ff4a66566c85c4af714403978bc07c50 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 29 May 2016 20:33:10 +0200 Subject: [PATCH] locks: printing date, what a hell in C :( --- locks/locks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/locks/locks.c b/locks/locks.c index 13661cd..75b8e16 100644 --- a/locks/locks.c +++ b/locks/locks.c @@ -183,7 +183,8 @@ int print_with_date(FILE *stream, const char *format, ...) va_list arg; int done; time_t rawtime; - char buff[50]; + char buff[100]; + char msg[50]; char dateformatter[100] = "%s: "; struct tm timeinfo; @@ -192,8 +193,11 @@ int print_with_date(FILE *stream, const char *format, ...) strftime(buff, 50, "%Y-%m-%d %H:%M:%S", &timeinfo); va_start (arg, format); - strcat(dateformatter, format); - done = fprintf (stream, dateformatter, buff, arg); + vsnprintf (msg , 50, format, arg); + + strcat(dateformatter, msg); + done = fprintf (stream, dateformatter, buff, msg); + va_end (arg); if (done < 0) { fflush (stream); -- 2.1.4