Skip to content

Commit

Permalink
Fix up totally buggered read_or_die()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Jan 12, 2007
1 parent d34cf19 commit 4494c65
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions write_or_die.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit 4494c65

Please sign in to comment.