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

Side by Side Diff: base/platform_file_posix.cc

Issue 213473007: Implement Read/WriteAtCurrentPos correctly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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/files/file_posix.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 254 }
255 255
256 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) { 256 int ReadPlatformFileAtCurrentPos(PlatformFile file, char* data, int size) {
257 base::ThreadRestrictions::AssertIOAllowed(); 257 base::ThreadRestrictions::AssertIOAllowed();
258 if (file < 0 || size < 0) 258 if (file < 0 || size < 0)
259 return -1; 259 return -1;
260 260
261 int bytes_read = 0; 261 int bytes_read = 0;
262 int rv; 262 int rv;
263 do { 263 do {
264 rv = HANDLE_EINTR(read(file, data, size)); 264 rv = HANDLE_EINTR(read(file, data + bytes_read, size - bytes_read));
265 if (rv <= 0) 265 if (rv <= 0)
266 break; 266 break;
267 267
268 bytes_read += rv; 268 bytes_read += rv;
269 } while (bytes_read < size); 269 } while (bytes_read < size);
270 270
271 return bytes_read ? bytes_read : rv; 271 return bytes_read ? bytes_read : rv;
272 } 272 }
273 273
274 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset, 274 int ReadPlatformFileNoBestEffort(PlatformFile file, int64 offset,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 315
316 int WritePlatformFileAtCurrentPos(PlatformFile file, 316 int WritePlatformFileAtCurrentPos(PlatformFile file,
317 const char* data, int size) { 317 const char* data, int size) {
318 base::ThreadRestrictions::AssertIOAllowed(); 318 base::ThreadRestrictions::AssertIOAllowed();
319 if (file < 0 || size < 0) 319 if (file < 0 || size < 0)
320 return -1; 320 return -1;
321 321
322 int bytes_written = 0; 322 int bytes_written = 0;
323 int rv; 323 int rv;
324 do { 324 do {
325 rv = HANDLE_EINTR(write(file, data, size)); 325 rv = HANDLE_EINTR(write(file, data + bytes_written, size - bytes_written));
326 if (rv <= 0) 326 if (rv <= 0)
327 break; 327 break;
328 328
329 bytes_written += rv; 329 bytes_written += rv;
330 } while (bytes_written < size); 330 } while (bytes_written < size);
331 331
332 return bytes_written ? bytes_written : rv; 332 return bytes_written ? bytes_written : rv;
333 } 333 }
334 334
335 int WritePlatformFileCurPosNoBestEffort(PlatformFile file, 335 int WritePlatformFileCurPosNoBestEffort(PlatformFile file,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 default: 456 default:
457 #if !defined(OS_NACL) // NaCl build has no metrics code. 457 #if !defined(OS_NACL) // NaCl build has no metrics code.
458 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", 458 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix",
459 saved_errno); 459 saved_errno);
460 #endif 460 #endif
461 return PLATFORM_FILE_ERROR_FAILED; 461 return PLATFORM_FILE_ERROR_FAILED;
462 } 462 }
463 } 463 }
464 464
465 } // namespace base 465 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698