| OLD | NEW |
| 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/files/file.h" | 5 #include "base/files/file.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 259 |
| 260 int File::ReadAtCurrentPos(char* data, int size) { | 260 int File::ReadAtCurrentPos(char* data, int size) { |
| 261 base::ThreadRestrictions::AssertIOAllowed(); | 261 base::ThreadRestrictions::AssertIOAllowed(); |
| 262 DCHECK(IsValid()); | 262 DCHECK(IsValid()); |
| 263 if (size < 0) | 263 if (size < 0) |
| 264 return -1; | 264 return -1; |
| 265 | 265 |
| 266 int bytes_read = 0; | 266 int bytes_read = 0; |
| 267 int rv; | 267 int rv; |
| 268 do { | 268 do { |
| 269 rv = HANDLE_EINTR(read(file_.get(), data, size)); | 269 rv = HANDLE_EINTR(read(file_.get(), data + bytes_read, size - bytes_read)); |
| 270 if (rv <= 0) | 270 if (rv <= 0) |
| 271 break; | 271 break; |
| 272 | 272 |
| 273 bytes_read += rv; | 273 bytes_read += rv; |
| 274 } while (bytes_read < size); | 274 } while (bytes_read < size); |
| 275 | 275 |
| 276 return bytes_read ? bytes_read : rv; | 276 return bytes_read ? bytes_read : rv; |
| 277 } | 277 } |
| 278 | 278 |
| 279 int File::ReadNoBestEffort(int64 offset, char* data, int size) { | 279 int File::ReadNoBestEffort(int64 offset, char* data, int size) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 318 |
| 319 int File::WriteAtCurrentPos(const char* data, int size) { | 319 int File::WriteAtCurrentPos(const char* data, int size) { |
| 320 base::ThreadRestrictions::AssertIOAllowed(); | 320 base::ThreadRestrictions::AssertIOAllowed(); |
| 321 DCHECK(IsValid()); | 321 DCHECK(IsValid()); |
| 322 if (size < 0) | 322 if (size < 0) |
| 323 return -1; | 323 return -1; |
| 324 | 324 |
| 325 int bytes_written = 0; | 325 int bytes_written = 0; |
| 326 int rv; | 326 int rv; |
| 327 do { | 327 do { |
| 328 rv = HANDLE_EINTR(write(file_.get(), data, size)); | 328 rv = HANDLE_EINTR(write(file_.get(), data + bytes_written, |
| 329 size - bytes_written)); |
| 329 if (rv <= 0) | 330 if (rv <= 0) |
| 330 break; | 331 break; |
| 331 | 332 |
| 332 bytes_written += rv; | 333 bytes_written += rv; |
| 333 } while (bytes_written < size); | 334 } while (bytes_written < size); |
| 334 | 335 |
| 335 return bytes_written ? bytes_written : rv; | 336 return bytes_written ? bytes_written : rv; |
| 336 } | 337 } |
| 337 | 338 |
| 338 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { | 339 int File::WriteAtCurrentPosNoBestEffort(const char* data, int size) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 return FILE_ERROR_FAILED; | 475 return FILE_ERROR_FAILED; |
| 475 } | 476 } |
| 476 } | 477 } |
| 477 | 478 |
| 478 void File::SetPlatformFile(PlatformFile file) { | 479 void File::SetPlatformFile(PlatformFile file) { |
| 479 DCHECK(!file_.is_valid()); | 480 DCHECK(!file_.is_valid()); |
| 480 file_.reset(file); | 481 file_.reset(file); |
| 481 } | 482 } |
| 482 | 483 |
| 483 } // namespace base | 484 } // namespace base |
| OLD | NEW |