From 17d7f9e8e6e5e41ef3411728671e414319726727 Mon Sep 17 00:00:00 2001 From: Luke Bratch Date: Tue, 9 Jul 2019 22:49:48 +0100 Subject: Make sure debug lines printed to file end with a trailing newline. --- functions.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'functions.c') diff --git a/functions.c b/functions.c index ad92dd3..a67776f 100644 --- a/functions.c +++ b/functions.c @@ -119,6 +119,14 @@ void debugprint(int level, char *format, ...) { if ((bytes = vfprintf(fp, format, args)) < 0) { debugprint(DEBUG_CRIT, "error: could not write to debug file.\n"); // TODO - This might not be useful if we can't write } + + // Make sure the finished log line ended with a trailing newline + if (format[strlen(format) - 1] != '\n') { + if ((bytes = fprintf(fp, "%c", '\n')) < 0) { + debugprint(DEBUG_CRIT, "error: could not write trailing newline to debug file.\n"); // TODO - This might not be useful if we can't write + } + } + fclose(fp); va_end(args); -- cgit v1.2.3