summaryrefslogtreecommitdiff
path: root/Userland/cp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/cp.cpp')
-rw-r--r--Userland/cp.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/Userland/cp.cpp b/Userland/cp.cpp
index db5c08b2d9..d8d9fdb419 100644
--- a/Userland/cp.cpp
+++ b/Userland/cp.cpp
@@ -29,12 +29,18 @@ int main(int argc, char** argv)
}
if (nread == 0)
break;
- ssize_t nwritten = write(dst_fd, buffer, nread);
- if (nwritten < 0) {
- perror("write dst");
- return 1;
+ ssize_t remaining_to_write = nread;
+ char* bufptr = buffer;
+ while (remaining_to_write) {
+ ssize_t nwritten = write(dst_fd, bufptr, remaining_to_write);
+ if (nwritten < 0) {
+ perror("write dst");
+ return 1;
+ }
+ assert(nwritten > 0);
+ remaining_to_write -= nwritten;
+ bufptr += nwritten;
}
- assert(nwritten != 0);
}
close(src_fd);
close(dst_fd);