libc_noux: fix 'read()' function

This patch fixes the problem that data in the read buffer would get
overwritten in cases where multiple 'read()' syscalls are necessary.

Fixes #303.
This commit is contained in:
Christian Prochaska 2012-07-27 17:20:33 +02:00 committed by Norman Feske
parent d6d45f870e
commit fa541b4545

View File

@ -664,7 +664,7 @@ namespace {
{ {
Genode::size_t sum_read_count = 0; Genode::size_t sum_read_count = 0;
while (count) { while (count > 0) {
Genode::size_t curr_count = Genode::size_t curr_count =
Genode::min(count, sizeof(sysio()->read_out.chunk)); Genode::min(count, sizeof(sysio()->read_out.chunk));
@ -678,11 +678,13 @@ namespace {
return -1; return -1;
} }
Genode::memcpy(buf, sysio()->read_out.chunk, sysio()->read_out.count); Genode::memcpy((char*)buf + sum_read_count,
sysio()->read_out.chunk,
sysio()->read_out.count);
sum_read_count += sysio()->read_out.count; sum_read_count += sysio()->read_out.count;
if (sysio()->read_out.count < sysio()->read_in.count) if (sysio()->read_out.count < curr_count)
break; /* end of file */ break; /* end of file */
if (sysio()->read_out.count <= count) if (sysio()->read_out.count <= count)