pkt-line: add packet_write function
Add a function which can be used to write the contents of an arbitrary buffer. This makes it easy to build up data in a buffer before writing the packet instead of formatting the entire contents of the packet using 'packet_write_fmt()'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Oct 16, 2017 at 10:55 UTC
5d2124b34a11967b56bfeb57556be5e4583172c8
2 files changed
+7
pkt-line.c
+6
@@ -188,6 +188,12 @@ static int packet_write_gently(const int fd_out, const char *buf, size_t size)
188
return 0;
189
}
190
191
+void packet_write(int fd_out, const char *buf, size_t size)
192
+{
193
+ if (packet_write_gently(fd_out, buf, size))
194
+ die_errno("packet write failed");
195
+}
196
+
197
void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
198
{
199
va_list args;
pkt-line.h
+1
@@ -22,6 +22,7 @@
22
void packet_flush(int fd);
23
void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
24
void packet_buf_flush(struct strbuf *buf);
25
+void packet_write(int fd_out, const char *buf, size_t size);
26
void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
27
int packet_flush_gently(int fd);
28
int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));