diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-26 22:17:19 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-26 22:17:19 +0000 |
commit | 29b5121000536bc5b11488a6235ef66302265ec5 (patch) | |
tree | ad91611ccf0f06a2bbf7fd0a0920a40c7e378b1d /base/platform_file_posix.cc | |
parent | 5e36e7f06e1be8b93ecdd09acfc0f26ea3177fb2 (diff) | |
download | chromium_src-29b5121000536bc5b11488a6235ef66302265ec5.zip chromium_src-29b5121000536bc5b11488a6235ef66302265ec5.tar.gz chromium_src-29b5121000536bc5b11488a6235ef66302265ec5.tar.bz2 |
Base: WritePlatformFile now retries the operation if
the OS writes less than expected (for POSIX).
BUG=94161
TEST=none
Review URL: http://codereview.chromium.org/7745008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98497 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/platform_file_posix.cc')
-rw-r--r-- | base/platform_file_posix.cc | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/base/platform_file_posix.cc b/base/platform_file_posix.cc index fed3696..b058edc 100644 --- a/base/platform_file_posix.cc +++ b/base/platform_file_posix.cc @@ -155,10 +155,21 @@ int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { int WritePlatformFile(PlatformFile file, int64 offset, const char* data, int size) { - if (file < 0) + if (file < 0 || size < 0) return -1; - return HANDLE_EINTR(pwrite(file, data, size, offset)); + int bytes_written = 0; + int rv; + do { + rv = HANDLE_EINTR(pwrite(file, data + bytes_written, + size - bytes_written, offset + bytes_written)); + if (rv <= 0) + break; + + bytes_written += rv; + } while (bytes_written < size); + + return bytes_written ? bytes_written : rv; } bool TruncatePlatformFile(PlatformFile file, int64 length) { |