summaryrefslogtreecommitdiff
path: root/write-or-die.c
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2021-09-01 12:54:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-09-01 17:20:39 (GMT)
commit96328398b3803c96f6a91edc39ccebd4bb9dd12c (patch)
tree66665c9a45b013b17f680224eab183301736045c /write-or-die.c
parentc4203212e360b25a1c69467b5a8437d45a373cac (diff)
downloadgit-96328398b3803c96f6a91edc39ccebd4bb9dd12c.zip
git-96328398b3803c96f6a91edc39ccebd4bb9dd12c.tar.gz
git-96328398b3803c96f6a91edc39ccebd4bb9dd12c.tar.bz2
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.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/write-or-die.c b/write-or-die.c
index d33e68f..0b1ec81 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");
+}