aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@shadowen.org>2007-01-08 15:58:23 +0000
committerJunio C Hamano <junkio@cox.net>2007-01-08 15:44:47 -0800
commit93822c2239a336e5cb583549071c59202ef6c5b2 (patch)
treef0c0a11adb226671e6e71803fa7d41d274aa7807 /sha1_file.c
parent93d26e4cb9cec2eb8abb4f37e6dda2c86fcceeac (diff)
downloadgit-93822c2239a336e5cb583549071c59202ef6c5b2.tar.gz
git-93822c2239a336e5cb583549071c59202ef6c5b2.tar.xz
short i/o: fix calls to write to use xwrite or write_in_full
We have a number of badly checked write() calls. Often we are expecting write() to write exactly the size we requested or fail, this fails to handle interrupts or short writes. Switch to using the new write_in_full(). Otherwise we at a minimum need to check for EINTR and EAGAIN, where this is appropriate use xwrite(). Note, the changes to config handling are much larger and handled in the next patch in the sequence. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 0c9483c5c..095a7e162 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1611,20 +1611,13 @@ int move_temp_to_file(const char *tmpfile, const char *filename)
static int write_buffer(int fd, const void *buf, size_t len)
{
- while (len) {
- ssize_t size;
+ ssize_t size;
- size = write(fd, buf, len);
- if (!size)
- return error("file write: disk full");
- if (size < 0) {
- if (errno == EINTR || errno == EAGAIN)
- continue;
- return error("file write error (%s)", strerror(errno));
- }
- len -= size;
- buf = (char *) buf + size;
- }
+ size = write_in_full(fd, buf, len);
+ if (!size)
+ return error("file write: disk full");
+ if (size < 0)
+ return error("file write error (%s)", strerror(errno));
return 0;
}