Skip to content

Commit 4c95e3d

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 564bde9 commit 4c95e3d

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

pkt-line.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ void packet_flush(int fd)
9494
int packet_flush_gently(int fd)
9595
{
9696
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;
100100
}
101101

102102
void packet_buf_flush(struct strbuf *buf)
@@ -137,18 +137,17 @@ static int packet_write_fmt_1(int fd, int gently,
137137
const char *fmt, va_list args)
138138
{
139139
struct strbuf buf = STRBUF_INIT;
140-
ssize_t count;
141140

142141
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");
150148
}
151-
return error("packet write with format failed");
149+
150+
return 0;
152151
}
153152

154153
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)
183182
packet_size = size + 4;
184183
set_packet_header(packet_write_buffer, packet_size);
185184
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;
189188
}
190189

191190
void packet_buf_write(struct strbuf *buf, const char *fmt, ...)

0 commit comments

Comments
 (0)