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/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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 bytes_written_partial = | 657 bytes_written_partial = |
658 HANDLE_EINTR(write(fd, data + bytes_written_total, | 658 HANDLE_EINTR(write(fd, data + bytes_written_total, |
659 size - bytes_written_total)); | 659 size - bytes_written_total)); |
660 if (bytes_written_partial < 0) | 660 if (bytes_written_partial < 0) |
661 return -1; | 661 return -1; |
662 } | 662 } |
663 | 663 |
664 return bytes_written_total; | 664 return bytes_written_total; |
665 } | 665 } |
666 | 666 |
| 667 int AppendToFile(const FilePath& filename, const char* data, int size) { |
| 668 base::ThreadRestrictions::AssertIOAllowed(); |
| 669 int fd = HANDLE_EINTR(open(filename.value().c_str(), O_WRONLY | O_APPEND)); |
| 670 if (fd < 0) |
| 671 return -1; |
| 672 |
| 673 int bytes_written = WriteFileDescriptor(fd, data, size); |
| 674 if (int ret = HANDLE_EINTR(close(fd)) < 0) |
| 675 return ret; |
| 676 return bytes_written; |
| 677 } |
| 678 |
667 // Gets the current working directory for the process. | 679 // Gets the current working directory for the process. |
668 bool GetCurrentDirectory(FilePath* dir) { | 680 bool GetCurrentDirectory(FilePath* dir) { |
669 // getcwd can return ENOENT, which implies it checks against the disk. | 681 // getcwd can return ENOENT, which implies it checks against the disk. |
670 base::ThreadRestrictions::AssertIOAllowed(); | 682 base::ThreadRestrictions::AssertIOAllowed(); |
671 | 683 |
672 char system_buffer[PATH_MAX] = ""; | 684 char system_buffer[PATH_MAX] = ""; |
673 if (!getcwd(system_buffer, sizeof(system_buffer))) { | 685 if (!getcwd(system_buffer, sizeof(system_buffer))) { |
674 NOTREACHED(); | 686 NOTREACHED(); |
675 return false; | 687 return false; |
676 } | 688 } |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 | 1114 |
1103 allowed_group_ids.insert(group_record->gr_gid); | 1115 allowed_group_ids.insert(group_record->gr_gid); |
1104 } | 1116 } |
1105 | 1117 |
1106 return VerifyPathControlledByUser( | 1118 return VerifyPathControlledByUser( |
1107 kFileSystemRoot, path, kRootUid, allowed_group_ids); | 1119 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
1108 } | 1120 } |
1109 #endif // defined(OS_MACOSX) | 1121 #endif // defined(OS_MACOSX) |
1110 | 1122 |
1111 } // namespace file_util | 1123 } // namespace file_util |
OLD | NEW |