diff options
author | Linus Torvalds <torvalds@osdl.org> | 2007-01-11 20:23:00 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-01-11 21:02:58 -0800 |
commit | d34cf19b8987ae0f0806e257edf877238d044747 (patch) | |
tree | 62c54c75d209587d44efc0528bd04d7cd8a8f472 /write_or_die.c | |
parent | 9bbaa6cc6848b68b8bef681c2a22b57bbec3e914 (diff) | |
download | git-d34cf19b8987ae0f0806e257edf877238d044747.tar.gz git-d34cf19b8987ae0f0806e257edf877238d044747.tar.xz |
Clean up write_in_full() users
With the new-and-improved write_in_full() semantics, where a partial write
simply always returns a real error (and always sets 'errno' when that
happens, including for the disk full case), a lot of the callers of
write_in_full() were just unnecessarily complex.
In particular, there's no reason to ever check for a zero length or
return: if the length was zero, we'll return zero, otherwise, if a disk
full resulted in the actual write() system call returning zero the
write_in_full() logic would have correctly turned that into a negative
return value, with 'errno' set to ENOSPC.
I really wish every "write_in_full()" user would just check against "<0"
now, but this fixes the nasty and stupid ones.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'write_or_die.c')
-rw-r--r-- | write_or_die.c | 31 |
1 files changed, 3 insertions, 28 deletions
diff --git a/write_or_die.c b/write_or_die.c index 488de721d..1224cac5d 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -58,14 +58,7 @@ int write_in_full(int fd, const void *buf, size_t count) void write_or_die(int fd, const void *buf, size_t count) { - ssize_t written; - - if (!count) - return; - written = write_in_full(fd, buf, count); - if (written == 0) - die("disk full?"); - else if (written < 0) { + if (write_in_full(fd, buf, count) < 0) { if (errno == EPIPE) exit(0); die("write error (%s)", strerror(errno)); @@ -74,16 +67,7 @@ void write_or_die(int fd, const void *buf, size_t count) int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg) { - ssize_t written; - - if (!count) - return 1; - written = write_in_full(fd, buf, count); - if (written == 0) { - fprintf(stderr, "%s: disk full?\n", msg); - return 0; - } - else if (written < 0) { + if (write_in_full(fd, buf, count) < 0) { if (errno == EPIPE) exit(0); fprintf(stderr, "%s: write error (%s)\n", @@ -96,16 +80,7 @@ int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg) int write_or_whine(int fd, const void *buf, size_t count, const char *msg) { - ssize_t written; - - if (!count) - return 1; - written = write_in_full(fd, buf, count); - if (written == 0) { - fprintf(stderr, "%s: disk full?\n", msg); - return 0; - } - else if (written < 0) { + if (write_in_full(fd, buf, count) < 0) { fprintf(stderr, "%s: write error (%s)\n", msg, strerror(errno)); return 0; |