summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-01-27 10:04:53 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-01-27 10:04:53 +0100
commitc4c475b49d98c8ae330a57a2ece95f4e90ef9575 (patch)
tree72f6532b11a80e250695736aa00f0dec0651da2e
parent32755aeb605a1b46383af4e3cd1674c75ae0585d (diff)
downloadserenity-c4c475b49d98c8ae330a57a2ece95f4e90ef9575.zip
/bin/cp: Handle partial write() case.
-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);