Skip to content

Commit

Permalink
chapters/io: Fix rread() and wwrite() logic
Browse files Browse the repository at this point in the history
As per `read()` and `write()` syscall wrappers documentation,
the return value of a successful operation is the count of bytes
read/written that could be less than the length given as param.

Signed-off-by: Andrei Adrian Ragman <[email protected]>
  • Loading branch information
andrei811 authored and teodutu committed Dec 12, 2024
1 parent 706610f commit 8ed7087
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ size_t rread(int fd, void *buf, size_t size)
size_t total_bytes_read = 0;

while (true) {
bytes_read = read(fd, buf, size);
bytes_read = read(fd, buf + total_bytes_read, size - total_bytes_read);
DIE(bytes_read < 0, "read");

if (bytes_read == 0)
Expand Down Expand Up @@ -57,7 +57,7 @@ size_t wwrite(int fd, const void *buf, size_t size)
size_t total_bytes_written = 0;

while (true) {
bytes_written = write(fd, buf, size);
bytes_written = write(fd, buf + total_bytes_written, size - total_bytes_written);
DIE(bytes_written < 0, "write");

total_bytes_written += bytes_written;
Expand Down

0 comments on commit 8ed7087

Please sign in to comment.