prefer xwrite instead of write

Our xwrite wrapper already deals with a few potential hazards, and are as such more robust. Prefer it instead of write to get the robustness benefits everywhere. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Reviewed-and-improved-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erik Faye-Lund committed Jan 17, 2014 at 15:17 UTC 7edc02f4deedb3a11abeb328dc2596b2886c2f47
3 files changed +4 -5
builtin/merge.c
+1 -1
@@ -367,7 +367,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
367 sha1_to_hex(commit->object.sha1));
368 pretty_print_commit(&ctx, commit, &out);
369 }
370 - if (write(fd, out.buf, out.len) < 0)
370 + if (write_in_full(fd, out.buf, out.len) != out.len)
371 die_errno(_("Writing SQUASH_MSG"));
372 if (close(fd))
373 die_errno(_("Finishing SQUASH_MSG"));
streaming.c
+1 -1
@@ -538,7 +538,7 @@ int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *f
538 goto close_and_exit;
539 }
540 if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 ||
541 - write(fd, "", 1) != 1))
541 + xwrite(fd, "", 1) != 1))
542 goto close_and_exit;
543 result = 0;
544
transport-helper.c
+2 -3
@@ -1129,9 +1129,8 @@ static int udt_do_write(struct unidirectional_transfer *t)
1129 return 0; /* Nothing to write. */
1130
1131 transfer_debug("%s is writable", t->dest_name);
1132 - bytes = write(t->dest, t->buf, t->bufuse);
1133 - if (bytes < 0 && errno != EWOULDBLOCK && errno != EAGAIN &&
1134 - errno != EINTR) {
1132 + bytes = xwrite(t->dest, t->buf, t->bufuse);
1133 + if (bytes < 0 && errno != EWOULDBLOCK) {
1134 error("write(%s) failed: %s", t->dest_name, strerror(errno));
1135 return -1;
1136 } else if (bytes > 0) {