Skip to content

Commit 7edc02f

Browse files
kusmagitster
authored andcommitted
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 <[email protected]> Reviewed-and-improved-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4224916 commit 7edc02f

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
367367
sha1_to_hex(commit->object.sha1));
368368
pretty_print_commit(&ctx, commit, &out);
369369
}
370-
if (write(fd, out.buf, out.len) < 0)
370+
if (write_in_full(fd, out.buf, out.len) != out.len)
371371
die_errno(_("Writing SQUASH_MSG"));
372372
if (close(fd))
373373
die_errno(_("Finishing SQUASH_MSG"));

streaming.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *f
538538
goto close_and_exit;
539539
}
540540
if (kept && (lseek(fd, kept - 1, SEEK_CUR) == (off_t) -1 ||
541-
write(fd, "", 1) != 1))
541+
xwrite(fd, "", 1) != 1))
542542
goto close_and_exit;
543543
result = 0;
544544

transport-helper.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,8 @@ static int udt_do_write(struct unidirectional_transfer *t)
11291129
return 0; /* Nothing to write. */
11301130

11311131
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) {
11351134
error("write(%s) failed: %s", t->dest_name, strerror(errno));
11361135
return -1;
11371136
} else if (bytes > 0) {

0 commit comments

Comments
 (0)