Index: base/platform_file_posix.cc |
=================================================================== |
--- base/platform_file_posix.cc (revision 97736) |
+++ base/platform_file_posix.cc (working copy) |
@@ -155,10 +155,22 @@ |
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 = -1; |
+ while (bytes_written < size) { |
+ rv = HANDLE_EINTR(pwrite(file, data + bytes_written, |
+ size - bytes_written, offset + bytes_written)); |
+ |
+ if (rv <= 0) |
+ break; |
+ |
+ bytes_written += rv; |
+ } |
+ |
+ return bytes_written ? bytes_written : (size ? rv : 0); |
Scott Hess - ex-Googler
2011/08/25 21:05:23
If !bytes_written && !size, then rv<=0, so I think
rvargas (doing something else)
2011/08/25 21:28:06
I want to return 0 instead of -1 (rv) if !size, an
Scott Hess - ex-Googler
2011/08/25 21:33:01
This means that the code changes to always return
rvargas (doing something else)
2011/08/25 21:37:50
No, that's not what I meant... fixing it.
|
} |
bool TruncatePlatformFile(PlatformFile file, int64 length) { |