Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: base/platform_file_posix.cc

Issue 7745008: Base: WritePlatformFile now retries the operation if (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/platform_file.h" 5 #include "base/platform_file.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) { 149 int ReadPlatformFile(PlatformFile file, int64 offset, char* data, int size) {
150 if (file < 0) 150 if (file < 0)
151 return -1; 151 return -1;
152 152
153 return HANDLE_EINTR(pread(file, data, size, offset)); 153 return HANDLE_EINTR(pread(file, data, size, offset));
154 } 154 }
155 155
156 int WritePlatformFile(PlatformFile file, int64 offset, 156 int WritePlatformFile(PlatformFile file, int64 offset,
157 const char* data, int size) { 157 const char* data, int size) {
158 if (file < 0) 158 if (file < 0 || size < 0)
159 return -1; 159 return -1;
160 160
161 return HANDLE_EINTR(pwrite(file, data, size, offset)); 161 int bytes_written = 0;
162 int rv;
163 do {
164 rv = HANDLE_EINTR(pwrite(file, data + bytes_written,
165 size - bytes_written, offset + bytes_written));
166 if (rv <= 0)
167 break;
168
169 bytes_written += rv;
170 } while (bytes_written < size);
171
172 return bytes_written ? bytes_written : rv;
162 } 173 }
163 174
164 bool TruncatePlatformFile(PlatformFile file, int64 length) { 175 bool TruncatePlatformFile(PlatformFile file, int64 length) {
165 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length))); 176 return ((file >= 0) && !HANDLE_EINTR(ftruncate(file, length)));
166 } 177 }
167 178
168 bool FlushPlatformFile(PlatformFile file) { 179 bool FlushPlatformFile(PlatformFile file) {
169 return !HANDLE_EINTR(fsync(file)); 180 return !HANDLE_EINTR(fsync(file));
170 } 181 }
171 182
(...skipping 19 matching lines...) Expand all
191 info->is_directory = S_ISDIR(file_info.st_mode); 202 info->is_directory = S_ISDIR(file_info.st_mode);
192 info->is_symbolic_link = S_ISLNK(file_info.st_mode); 203 info->is_symbolic_link = S_ISLNK(file_info.st_mode);
193 info->size = file_info.st_size; 204 info->size = file_info.st_size;
194 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); 205 info->last_modified = base::Time::FromTimeT(file_info.st_mtime);
195 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); 206 info->last_accessed = base::Time::FromTimeT(file_info.st_atime);
196 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); 207 info->creation_time = base::Time::FromTimeT(file_info.st_ctime);
197 return true; 208 return true;
198 } 209 }
199 210
200 } // namespace base 211 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698