@matheusbsbs / matheus-bagliano / commits / 4494c656e2
Fork 0

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>

Linus Torvalds committed Jan 11, 2007 at 20:37 UTC 4494c656e2e29c468c48c9c2b20595342056e9dc
1 file changed +8 -14
write_or_die.c
+8 -14
@@ -4,16 +4,11 @@ int read_in_full(int fd, void *buf, size_t count)
4 {
5 char *p = buf;
6 ssize_t total = 0;
7 - ssize_t loaded = 0;
7
8 while (count > 0) {
10 - loaded = xread(fd, p, count);
11 - if (loaded <= 0) {
12 - if (total)
13 - return total;
14 - else
15 - return loaded;
16 - }
9 + ssize_t loaded = xread(fd, p, count);
10 + if (loaded <= 0)
11 + return total ? total : loaded;
12 count -= loaded;
13 p += loaded;
14 total += loaded;
@@ -26,13 +21,12 @@ void read_or_die(int fd, void *buf, size_t count)
21 {
22 ssize_t loaded;
23
29 - if (!count)
30 - return;
24 loaded = read_in_full(fd, buf, count);
32 - if (loaded == 0)
33 - die("unexpected end of file");
34 - else if (loaded < 0)
35 - die("read error (%s)", strerror(errno));
25 + if (loaded != count) {
26 + if (loaded < 0)
27 + die("read error (%s)", strerror(errno));
28 + die("read error: end of file");
29 + }
30 }
31
32 int write_in_full(int fd, const void *buf, size_t count)