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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0640)); | 686 int fd = HANDLE_EINTR(creat(filename.value().c_str(), 0640)); |
687 if (fd < 0) | 687 if (fd < 0) |
688 return -1; | 688 return -1; |
689 | 689 |
690 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1; | 690 int bytes_written = WriteFileDescriptor(fd, data, size) ? size : -1; |
691 if (IGNORE_EINTR(close(fd)) < 0) | 691 if (IGNORE_EINTR(close(fd)) < 0) |
692 return -1; | 692 return -1; |
693 return bytes_written; | 693 return bytes_written; |
694 } | 694 } |
695 | 695 |
696 bool WriteFileMode(const FilePath& filename, const char* data, int size, | |
697 mode_t mode) { | |
698 ThreadRestrictions::AssertIOAllowed(); | |
699 int fd = HANDLE_EINTR(creat(filename.value().c_str(), mode)); | |
700 if (fd < 0) | |
701 return -1; | |
rvargas (doing something else)
2014/10/21 01:05:53
return false
palmer
2014/10/21 01:26:42
Done.
| |
702 | |
703 bool status = WriteFileDescriptor(fd, data, size); | |
704 if (IGNORE_EINTR(close(fd)) < 0) | |
rvargas (doing something else)
2014/10/21 01:05:53
nit: Now that we are writing this function from sc
palmer
2014/10/21 01:26:42
Done.
| |
705 return false; | |
706 return status; | |
707 } | |
708 | |
696 bool WriteFileDescriptor(const int fd, const char* data, int size) { | 709 bool WriteFileDescriptor(const int fd, const char* data, int size) { |
697 // Allow for partial writes. | 710 // Allow for partial writes. |
698 ssize_t bytes_written_total = 0; | 711 ssize_t bytes_written_total = 0; |
699 for (ssize_t bytes_written_partial = 0; bytes_written_total < size; | 712 for (ssize_t bytes_written_partial = 0; bytes_written_total < size; |
700 bytes_written_total += bytes_written_partial) { | 713 bytes_written_total += bytes_written_partial) { |
701 bytes_written_partial = | 714 bytes_written_partial = |
702 HANDLE_EINTR(write(fd, data + bytes_written_total, | 715 HANDLE_EINTR(write(fd, data + bytes_written_total, |
703 size - bytes_written_total)); | 716 size - bytes_written_total)); |
704 if (bytes_written_partial < 0) | 717 if (bytes_written_partial < 0) |
705 return false; | 718 return false; |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 result = false; | 934 result = false; |
922 | 935 |
923 return result; | 936 return result; |
924 } | 937 } |
925 #endif // !defined(OS_MACOSX) | 938 #endif // !defined(OS_MACOSX) |
926 | 939 |
927 } // namespace internal | 940 } // namespace internal |
928 | 941 |
929 #endif // !defined(__native_client_nonsfi__) | 942 #endif // !defined(__native_client_nonsfi__) |
930 } // namespace base | 943 } // namespace base |
OLD | NEW |