From 96328398b3803c96f6a91edc39ccebd4bb9dd12c Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Wed, 1 Sep 2021 14:54:41 +0200 Subject: pkt-line: add stdio packet write functions This adds three new functions to pkt-line.c: packet_fwrite, packet_fwrite_fmt and packet_fflush. Besides writing a pktline flush packet, packet_fflush also flushes the stdio buffer of the stream. Helped-by: Patrick Steinhardt Helped-by: Jeff King Signed-off-by: Jacob Vosmaer Signed-off-by: Junio C Hamano --- write-or-die.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'write-or-die.c') diff --git a/write-or-die.c b/write-or-die.c index d33e68f6ab..0b1ec8190b 100644 --- a/write-or-die.c +++ b/write-or-die.c @@ -70,3 +70,15 @@ void write_or_die(int fd, const void *buf, size_t count) die_errno("write error"); } } + +void fwrite_or_die(FILE *f, const void *buf, size_t count) +{ + if (fwrite(buf, 1, count, f) != count) + die_errno("fwrite error"); +} + +void fflush_or_die(FILE *f) +{ + if (fflush(f)) + die_errno("fflush error"); +} -- cgit v1.2.3