OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <fnmatch.h> | 10 #include <fnmatch.h> |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 int ret_value = HANDLE_EINTR(read(fd, data, size)); | 506 int ret_value = HANDLE_EINTR(read(fd, data, size)); |
507 HANDLE_EINTR(close(fd)); | 507 HANDLE_EINTR(close(fd)); |
508 return ret_value; | 508 return ret_value; |
509 } | 509 } |
510 | 510 |
511 int WriteFile(const FilePath& filename, const char* data, int size) { | 511 int WriteFile(const FilePath& filename, const char* data, int size) { |
512 int fd = creat(filename.value().c_str(), 0666); | 512 int fd = creat(filename.value().c_str(), 0666); |
513 if (fd < 0) | 513 if (fd < 0) |
514 return -1; | 514 return -1; |
515 | 515 |
516 // Allow for partial writes | 516 int rv = WriteFileDescriptor(fd, data, size); |
| 517 HANDLE_EINTR(close(fd)); |
| 518 return rv; |
| 519 } |
| 520 |
| 521 int WriteFileDescriptor(const int fd, const char* data, int size) { |
| 522 // Allow for partial writes. |
517 ssize_t bytes_written_total = 0; | 523 ssize_t bytes_written_total = 0; |
518 do { | 524 for (ssize_t bytes_written_partial = 0; bytes_written_total < size; |
519 ssize_t bytes_written_partial = | 525 bytes_written_total += bytes_written_partial) { |
520 HANDLE_EINTR(write(fd, data + bytes_written_total, | 526 bytes_written_partial = |
521 size - bytes_written_total)); | 527 HANDLE_EINTR(write(fd, data + bytes_written_total, |
522 if (bytes_written_partial < 0) { | 528 size - bytes_written_total)); |
523 HANDLE_EINTR(close(fd)); | 529 if (bytes_written_partial < 0) |
524 return -1; | 530 return -1; |
525 } | 531 } |
526 bytes_written_total += bytes_written_partial; | |
527 } while (bytes_written_total < size); | |
528 | 532 |
529 HANDLE_EINTR(close(fd)); | |
530 return bytes_written_total; | 533 return bytes_written_total; |
531 } | 534 } |
532 | 535 |
533 // Gets the current working directory for the process. | 536 // Gets the current working directory for the process. |
534 bool GetCurrentDirectory(FilePath* dir) { | 537 bool GetCurrentDirectory(FilePath* dir) { |
535 char system_buffer[PATH_MAX] = ""; | 538 char system_buffer[PATH_MAX] = ""; |
536 if (!getcwd(system_buffer, sizeof(system_buffer))) { | 539 if (!getcwd(system_buffer, sizeof(system_buffer))) { |
537 NOTREACHED(); | 540 NOTREACHED(); |
538 return false; | 541 return false; |
539 } | 542 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 munmap(data_, length_); | 738 munmap(data_, length_); |
736 if (file_ != -1) | 739 if (file_ != -1) |
737 close(file_); | 740 close(file_); |
738 | 741 |
739 data_ = NULL; | 742 data_ = NULL; |
740 length_ = 0; | 743 length_ = 0; |
741 file_ = -1; | 744 file_ = -1; |
742 } | 745 } |
743 | 746 |
744 } // namespace file_util | 747 } // namespace file_util |
OLD | NEW |