summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Lars Schneider <larsxschneider@gmail.com>2016-10-16 16:20:33 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-10-17 11:36:50 -0700
commitedfb780cd4fe73474583016055542f5686d3d98d (patch)
treef116ce8482464c3e5b375696a47d1bbf89909f3b
parentpkt-line: add packet_flush_gently() (diff)
downloadtgif-edfb780cd4fe73474583016055542f5686d3d98d.tar.xz
pkt-line: add packet_write_gently()
packet_write_fmt_gently() uses format_packet() which lets the caller only send string data via "%s". That means it cannot be used for arbitrary data that may contain NULs. Add packet_write_gently() which writes arbitrary data and does not die in case of an error. The function is used by other pkt-line functions in a subsequent patch. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--pkt-line.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkt-line.c b/pkt-line.c
index 62b89dbe3e..fef1059a68 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -171,6 +171,23 @@ int packet_write_fmt_gently(int fd, const char *fmt, ...)
return status;
}
+static int packet_write_gently(const int fd_out, const char *buf, size_t size)
+{
+ static char packet_write_buffer[LARGE_PACKET_MAX];
+ size_t packet_size;
+
+ if (size > sizeof(packet_write_buffer) - 4)
+ return error("packet write failed - data exceeds max packet size");
+
+ packet_trace(buf, size, 1);
+ packet_size = size + 4;
+ set_packet_header(packet_write_buffer, packet_size);
+ memcpy(packet_write_buffer + 4, buf, size);
+ if (write_in_full(fd_out, packet_write_buffer, packet_size) == packet_size)
+ return 0;
+ return error("packet write failed");
+}
+
void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
{
va_list args;