| Index: base/file_util_posix.cc
|
| ===================================================================
|
| --- base/file_util_posix.cc (revision 26285)
|
| +++ base/file_util_posix.cc (working copy)
|
| @@ -513,20 +513,23 @@
|
| if (fd < 0)
|
| return -1;
|
|
|
| - // Allow for partial writes
|
| + int rv = WriteFileDescriptor(fd, data, size);
|
| + HANDLE_EINTR(close(fd));
|
| + return rv;
|
| +}
|
| +
|
| +int WriteFileDescriptor(const int fd, const char* data, int size) {
|
| + // Allow for partial writes.
|
| ssize_t bytes_written_total = 0;
|
| - do {
|
| - ssize_t bytes_written_partial =
|
| - HANDLE_EINTR(write(fd, data + bytes_written_total,
|
| - size - bytes_written_total));
|
| - if (bytes_written_partial < 0) {
|
| - HANDLE_EINTR(close(fd));
|
| + for (ssize_t bytes_written_partial = 0; bytes_written_total < size;
|
| + bytes_written_total += bytes_written_partial) {
|
| + bytes_written_partial =
|
| + HANDLE_EINTR(write(fd, data + bytes_written_total,
|
| + size - bytes_written_total));
|
| + if (bytes_written_partial < 0)
|
| return -1;
|
| - }
|
| - bytes_written_total += bytes_written_partial;
|
| - } while (bytes_written_total < size);
|
| + }
|
|
|
| - HANDLE_EINTR(close(fd));
|
| return bytes_written_total;
|
| }
|
|
|
|
|