OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/platform_file.h" | 5 #include "base/platform_file.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } else if (flags & PLATFORM_FILE_WRITE) { | 73 } else if (flags & PLATFORM_FILE_WRITE) { |
74 open_flags |= O_WRONLY; | 74 open_flags |= O_WRONLY; |
75 } else if (!(flags & PLATFORM_FILE_READ) && | 75 } else if (!(flags & PLATFORM_FILE_READ) && |
76 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && | 76 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && |
77 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { | 77 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { |
78 NOTREACHED(); | 78 NOTREACHED(); |
79 } | 79 } |
80 | 80 |
81 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); | 81 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); |
82 | 82 |
| 83 int mode = S_IRUSR | S_IWUSR; |
| 84 #if defined(OS_CHROMEOS) |
| 85 mode |= S_IRGRP | S_IROTH; |
| 86 #endif |
| 87 |
83 int descriptor = | 88 int descriptor = |
84 HANDLE_EINTR(open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR)); | 89 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); |
85 | 90 |
86 if (flags & PLATFORM_FILE_OPEN_ALWAYS) { | 91 if (flags & PLATFORM_FILE_OPEN_ALWAYS) { |
87 if (descriptor <= 0) { | 92 if (descriptor <= 0) { |
88 open_flags |= O_CREAT; | 93 open_flags |= O_CREAT; |
89 if (flags & PLATFORM_FILE_EXCLUSIVE_READ || | 94 if (flags & PLATFORM_FILE_EXCLUSIVE_READ || |
90 flags & PLATFORM_FILE_EXCLUSIVE_WRITE) { | 95 flags & PLATFORM_FILE_EXCLUSIVE_WRITE) { |
91 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW | 96 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW |
92 } | 97 } |
93 descriptor = HANDLE_EINTR( | 98 descriptor = HANDLE_EINTR( |
94 open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR)); | 99 open(name.value().c_str(), open_flags, mode)); |
95 if (created && descriptor > 0) | 100 if (created && descriptor > 0) |
96 *created = true; | 101 *created = true; |
97 } | 102 } |
98 } | 103 } |
99 | 104 |
100 if (created && (descriptor > 0) && | 105 if (created && (descriptor > 0) && |
101 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE))) | 106 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE))) |
102 *created = true; | 107 *created = true; |
103 | 108 |
104 if ((descriptor > 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) { | 109 if ((descriptor > 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 info->is_directory = S_ISDIR(file_info.st_mode); | 237 info->is_directory = S_ISDIR(file_info.st_mode); |
233 info->is_symbolic_link = S_ISLNK(file_info.st_mode); | 238 info->is_symbolic_link = S_ISLNK(file_info.st_mode); |
234 info->size = file_info.st_size; | 239 info->size = file_info.st_size; |
235 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 240 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
236 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 241 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
237 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 242 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
238 return true; | 243 return true; |
239 } | 244 } |
240 | 245 |
241 } // namespace base | 246 } // namespace base |
OLD | NEW |