summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9bbaa6c)
raw | patch | inline | side by side (parent: 9bbaa6c)
author | Linus Torvalds <torvalds@osdl.org> | |
Fri, 12 Jan 2007 04:23:00 +0000 (20:23 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Fri, 12 Jan 2007 05:02:58 +0000 (21:02 -0800) |
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>
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>
sha1_file.c | patch | blob | history | |
write_or_die.c | patch | blob | history |
diff --git a/sha1_file.c b/sha1_file.c
index 18dd89b50a23a4a99b51d8e99d0c67cace2a1a2d..2a5be53faca4524f5a70e6e928044ba3aa402d8f 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
static int write_buffer(int fd, const void *buf, size_t len)
{
- ssize_t size;
-
- if (!len)
- return 0;
- size = write_in_full(fd, buf, len);
- if (!size)
- return error("file write: disk full");
- if (size < 0)
+ if (write_in_full(fd, buf, len) < 0)
return error("file write error (%s)", strerror(errno));
return 0;
}
diff --git a/write_or_die.c b/write_or_die.c
index 488de721da8a316c06bf53e9091633e5ac415390..1224cac5da7e8bf51266eadf24e9e58e6e5a37cb 100644 (file)
--- a/write_or_die.c
+++ b/write_or_die.c
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));
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",
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;