mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-12 17:37:53 +03:00
/bin/cp: Handle partial write() case.
This commit is contained in:
parent
32755aeb60
commit
c4c475b49d
Notes:
sideshowbarker
2024-07-19 15:55:59 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c4c475b49d9
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user