pkt-line: check write_in_full() errors against "< 0"

As with the previous two commits, we prefer to check write_in_full()'s return value to see if it is negative, rather than comparing it to the input length. These cases actually flip the logic to check for success, making conversion a little different than in other cases. We could of course write: if (write_in_full(...) >= 0) return 0; return error(...); But our usual method of spelling write() error checks is just "< 0". So let's flip the logic for each of these conditionals to our usual style. Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 13, 2017 at 13:17 UTC 4c95e3dd28342878e0deed264ddc784b775361b7
1 file changed +14 -15
pkt-line.c
+14 -15
@@ -94,9 +94,9 @@ void packet_flush(int fd)
94 int packet_flush_gently(int fd)
95 {
96 packet_trace("0000", 4, 1);
97 - if (write_in_full(fd, "0000", 4) == 4)
98 - return 0;
99 - return error("flush packet write failed");
97 + if (write_in_full(fd, "0000", 4) < 0)
98 + return error("flush packet write failed");
99 + return 0;
100 }
101
102 void packet_buf_flush(struct strbuf *buf)
@@ -137,18 +137,17 @@ static int packet_write_fmt_1(int fd, int gently,
137 const char *fmt, va_list args)
138 {
139 struct strbuf buf = STRBUF_INIT;
140 - ssize_t count;
140
141 format_packet(&buf, fmt, args);
143 - count = write_in_full(fd, buf.buf, buf.len);
144 - if (count == buf.len)
145 - return 0;
146 -
147 - if (!gently) {
148 - check_pipe(errno);
149 - die_errno("packet write with format failed");
142 + if (write_in_full(fd, buf.buf, buf.len) < 0) {
143 + if (!gently) {
144 + check_pipe(errno);
145 + die_errno("packet write with format failed");
146 + }
147 + return error("packet write with format failed");
148 }
151 - return error("packet write with format failed");
149 +
150 + return 0;
151 }
152
153 void packet_write_fmt(int fd, const char *fmt, ...)
@@ -183,9 +182,9 @@ static int packet_write_gently(const int fd_out, const char *buf, size_t size)
182 packet_size = size + 4;
183 set_packet_header(packet_write_buffer, packet_size);
184 memcpy(packet_write_buffer + 4, buf, size);
186 - if (write_in_full(fd_out, packet_write_buffer, packet_size) == packet_size)
187 - return 0;
188 - return error("packet write failed");
185 + if (write_in_full(fd_out, packet_write_buffer, packet_size) < 0)
186 + return error("packet write failed");
187 + return 0;
188 }
189
190 void packet_buf_write(struct strbuf *buf, const char *fmt, ...)