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_util.h" | 5 #include "base/files/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 <libgen.h> | 10 #include <libgen.h> |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 if (fd < 0) | 670 if (fd < 0) |
671 return -1; | 671 return -1; |
672 | 672 |
673 ssize_t bytes_read = HANDLE_EINTR(read(fd, data, max_size)); | 673 ssize_t bytes_read = HANDLE_EINTR(read(fd, data, max_size)); |
674 if (IGNORE_EINTR(close(fd)) < 0) | 674 if (IGNORE_EINTR(close(fd)) < 0) |
675 return -1; | 675 return -1; |
676 return bytes_read; | 676 return bytes_read; |
677 } | 677 } |
678 | 678 |
679 int WriteFile(const FilePath& filename, const char* data, int size) { | 679 int WriteFile(const FilePath& filename, const char* data, int size) { |
| 680 return WriteFileMode(filename, data, size, 0640); |
| 681 } |
| 682 |
| 683 int WriteFileMode(const FilePath& filename, const char* data, int size, |
| 684 mode_t mode) { |
680 ThreadRestrictions::AssertIOAllowed(); | 685 ThreadRestrictions::AssertIOAllowed(); |
681 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0640)); | 686 int fd = HANDLE_EINTR(creat(filename.value().c_str(), mode)); |
682 if (fd < 0) | 687 if (fd < 0) |
683 return -1; | 688 return -1; |
684 | 689 |
685 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1; | 690 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1; |
686 if (IGNORE_EINTR(close(fd)) < 0) | 691 if (IGNORE_EINTR(close(fd)) < 0) |
687 return -1; | 692 return -1; |
688 return bytes_written; | 693 return bytes_written; |
689 } | 694 } |
690 | 695 |
691 bool WriteFileDescriptor(const int fd, const char* data, int size) { | 696 bool WriteFileDescriptor(const int fd, const char* data, int size) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 result = false; | 919 result = false; |
915 if (IGNORE_EINTR(close(outfile)) < 0) | 920 if (IGNORE_EINTR(close(outfile)) < 0) |
916 result = false; | 921 result = false; |
917 | 922 |
918 return result; | 923 return result; |
919 } | 924 } |
920 #endif // !defined(OS_MACOSX) | 925 #endif // !defined(OS_MACOSX) |
921 | 926 |
922 } // namespace internal | 927 } // namespace internal |
923 } // namespace base | 928 } // namespace base |
OLD | NEW |