gems: loop on partial reads in file util

This commit is contained in:
Christian Helmuth 2018-01-26 11:34:32 +01:00 committed by Norman Feske
parent 666f6c9ac4
commit 4a444651c5

View File

@ -43,10 +43,19 @@ File::File(char const *name, Genode::Allocator &alloc)
{
Libc::with_libc([&] () {
int const fd = open(name, O_RDONLY);
if (read(fd, _data, _file_size) < 0) {
Genode::error("reading from file \"", name, "\" failed (error ", errno, ")");
throw Reading_failed();
}
Genode::size_t remain = _file_size;
char *data = (char *)_data;
do {
int ret;
if ((ret = read(fd, data, remain)) < 0) {
Genode::error("reading from file \"", name, "\" failed (error ", errno, ")");
throw Reading_failed();
}
remain -= ret;
data += ret;
} while (remain > 0);
close(fd);
});
}