diff options
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r-- | base/file_util_posix.cc | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index bd18a83..7c212c0 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -513,20 +513,23 @@ int WriteFile(const FilePath& filename, const char* data, int size) { 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; } |