diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2021-09-01 14:54:41 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-09-01 19:20:39 +0200 |
commit | 96328398b3803c96f6a91edc39ccebd4bb9dd12c (patch) | |
tree | 66665c9a45b013b17f680224eab183301736045c /write-or-die.c | |
parent | The first batch post 2.33 (diff) | |
download | git-96328398b3803c96f6a91edc39ccebd4bb9dd12c.tar.xz git-96328398b3803c96f6a91edc39ccebd4bb9dd12c.zip |
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 <ps@pks.im>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Jacob Vosmaer <jacob@gitlab.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'write-or-die.c')
-rw-r--r-- | write-or-die.c | 12 |
1 files changed, 12 insertions, 0 deletions
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"); +} |