From 6908189fc496f6acd8755a9b6f00270a7f352dcb Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 29 Dec 2023 21:32:42 +0100 Subject: Properly lock and unlock streams when printing --- cbs.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cbs.h b/cbs.h index 923737f..2f147c6 100644 --- a/cbs.h +++ b/cbs.h @@ -286,6 +286,7 @@ die(const char *fmt, ...) va_list ap; va_start(ap, fmt); + flockfile(stderr); fprintf(stderr, "%s: ", *_cbs_argv); if (fmt) { vfprintf(stderr, fmt, ap); @@ -301,6 +302,7 @@ diex(const char *fmt, ...) va_list ap; va_start(ap, fmt); + flockfile(stderr); fprintf(stderr, "%s: ", *_cbs_argv); if (fmt) vfprintf(stderr, fmt, ap); @@ -457,6 +459,7 @@ cmdput(cmd_t c) void cmdputf(FILE *stream, cmd_t cmd) { + flockfile(stream); for (size_t i = 0; i < cmd._len; i++) { bool safe = true; char *p, *q; @@ -484,6 +487,7 @@ cmdputf(FILE *stream, cmd_t cmd) putc(i == cmd._len - 1 ? '\n' : ' ', stream); } + funlockfile(stream); } bool -- cgit v1.2.3