mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-20 06:07:59 +00:00
gems: loop on partial reads in file util
This commit is contained in:
parent
666f6c9ac4
commit
4a444651c5
@ -43,10 +43,19 @@ File::File(char const *name, Genode::Allocator &alloc)
|
|||||||
{
|
{
|
||||||
Libc::with_libc([&] () {
|
Libc::with_libc([&] () {
|
||||||
int const fd = open(name, O_RDONLY);
|
int const fd = open(name, O_RDONLY);
|
||||||
if (read(fd, _data, _file_size) < 0) {
|
|
||||||
|
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, ")");
|
Genode::error("reading from file \"", name, "\" failed (error ", errno, ")");
|
||||||
throw Reading_failed();
|
throw Reading_failed();
|
||||||
}
|
}
|
||||||
|
remain -= ret;
|
||||||
|
data += ret;
|
||||||
|
} while (remain > 0);
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user