aboutsummaryrefslogtreecommitdiff
path: root/write_or_die.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@osdl.org>2007-01-11 20:37:38 -0800
committerJunio C Hamano <junkio@cox.net>2007-01-11 21:05:34 -0800
commit4494c656e2e29c468c48c9c2b20595342056e9dc (patch)
tree21dc0c3eb8efd6f15b5a797d15da2fe3fd1b44c4 /write_or_die.c
parentd34cf19b8987ae0f0806e257edf877238d044747 (diff)
downloadgit-4494c656e2e29c468c48c9c2b20595342056e9dc.tar.gz
git-4494c656e2e29c468c48c9c2b20595342056e9dc.tar.xz
Fix up totally buggered read_or_die()
The "read_or_die()" function would silently NOT die for a partial read, and since it was of type "void" it obviously couldn't even return the partial number of bytes read. IOW, it was totally broken. This hopefully fixes it up. 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.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/write_or_die.c b/write_or_die.c
index 1224cac5d..4e8183e93 100644
--- a/write_or_die.c
+++ b/write_or_die.c
@@ -4,16 +4,11 @@ int read_in_full(int fd, void *buf, size_t count)
{
char *p = buf;
ssize_t total = 0;
- ssize_t loaded = 0;
while (count > 0) {
- loaded = xread(fd, p, count);
- if (loaded <= 0) {
- if (total)
- return total;
- else
- return loaded;
- }
+ ssize_t loaded = xread(fd, p, count);
+ if (loaded <= 0)
+ return total ? total : loaded;
count -= loaded;
p += loaded;
total += loaded;
@@ -26,13 +21,12 @@ void read_or_die(int fd, void *buf, size_t count)
{
ssize_t loaded;
- if (!count)
- return;
loaded = read_in_full(fd, buf, count);
- if (loaded == 0)
- die("unexpected end of file");
- else if (loaded < 0)
- die("read error (%s)", strerror(errno));
+ if (loaded != count) {
+ if (loaded < 0)
+ die("read error (%s)", strerror(errno));
+ die("read error: end of file");
+ }
}
int write_in_full(int fd, const void *buf, size_t count)