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>
This commit is contained in:
Linus Torvalds 2007-01-11 20:37:38 -08:00 коммит произвёл Junio C Hamano
Родитель d34cf19b89
Коммит 4494c656e2
1 изменённых файлов: 8 добавлений и 14 удалений

Просмотреть файл

@ -4,16 +4,11 @@ int read_in_full(int fd, void *buf, size_t count)
{ {
char *p = buf; char *p = buf;
ssize_t total = 0; ssize_t total = 0;
ssize_t loaded = 0;
while (count > 0) { while (count > 0) {
loaded = xread(fd, p, count); ssize_t loaded = xread(fd, p, count);
if (loaded <= 0) { if (loaded <= 0)
if (total) return total ? total : loaded;
return total;
else
return loaded;
}
count -= loaded; count -= loaded;
p += loaded; p += loaded;
total += loaded; total += loaded;
@ -26,13 +21,12 @@ void read_or_die(int fd, void *buf, size_t count)
{ {
ssize_t loaded; ssize_t loaded;
if (!count)
return;
loaded = read_in_full(fd, buf, count); loaded = read_in_full(fd, buf, count);
if (loaded == 0) if (loaded != count) {
die("unexpected end of file"); if (loaded < 0)
else if (loaded < 0) die("read error (%s)", strerror(errno));
die("read error (%s)", strerror(errno)); die("read error: end of file");
}
} }
int write_in_full(int fd, const void *buf, size_t count) int write_in_full(int fd, const void *buf, size_t count)