pkt-line: add packet_write_gently()
[gitweb.git] / pkt-line.c
index 62b89dbe3ec2c294775b1956d4a857eb20fda405..fef1059a684a7517788c900c721d419ea26ec897 100644 (file)
@@ -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;