OLD | NEW |
1 // Copyright (c) 2011 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/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> |
11 | 11 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 int mode = S_IRUSR | S_IWUSR; | 83 int mode = S_IRUSR | S_IWUSR; |
84 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
85 mode |= S_IRGRP | S_IROTH; | 85 mode |= S_IRGRP | S_IROTH; |
86 #endif | 86 #endif |
87 | 87 |
88 int descriptor = | 88 int descriptor = |
89 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); | 89 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); |
90 | 90 |
91 if (flags & PLATFORM_FILE_OPEN_ALWAYS) { | 91 if (flags & PLATFORM_FILE_OPEN_ALWAYS) { |
92 if (descriptor <= 0) { | 92 if (descriptor < 0) { |
93 open_flags |= O_CREAT; | 93 open_flags |= O_CREAT; |
94 if (flags & PLATFORM_FILE_EXCLUSIVE_READ || | 94 if (flags & PLATFORM_FILE_EXCLUSIVE_READ || |
95 flags & PLATFORM_FILE_EXCLUSIVE_WRITE) { | 95 flags & PLATFORM_FILE_EXCLUSIVE_WRITE) { |
96 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW | 96 open_flags |= O_EXCL; // together with O_CREAT implies O_NOFOLLOW |
97 } | 97 } |
98 descriptor = HANDLE_EINTR( | 98 descriptor = HANDLE_EINTR( |
99 open(name.value().c_str(), open_flags, mode)); | 99 open(name.value().c_str(), open_flags, mode)); |
100 if (created && descriptor > 0) | 100 if (created && descriptor >= 0) |
101 *created = true; | 101 *created = true; |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 if (created && (descriptor > 0) && | 105 if (created && (descriptor >= 0) && |
106 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE))) | 106 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE))) |
107 *created = true; | 107 *created = true; |
108 | 108 |
109 if ((descriptor > 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) { | 109 if ((descriptor >= 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) { |
110 unlink(name.value().c_str()); | 110 unlink(name.value().c_str()); |
111 } | 111 } |
112 | 112 |
113 if (error_code) { | 113 if (error_code) { |
114 if (descriptor >= 0) | 114 if (descriptor >= 0) |
115 *error_code = PLATFORM_FILE_OK; | 115 *error_code = PLATFORM_FILE_OK; |
116 else { | 116 else { |
117 switch (errno) { | 117 switch (errno) { |
118 case EACCES: | 118 case EACCES: |
119 case EISDIR: | 119 case EISDIR: |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 info->is_directory = S_ISDIR(file_info.st_mode); | 237 info->is_directory = S_ISDIR(file_info.st_mode); |
238 info->is_symbolic_link = S_ISLNK(file_info.st_mode); | 238 info->is_symbolic_link = S_ISLNK(file_info.st_mode); |
239 info->size = file_info.st_size; | 239 info->size = file_info.st_size; |
240 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); | 240 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); |
241 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); | 241 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); |
242 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); | 242 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); |
243 return true; | 243 return true; |
244 } | 244 } |
245 | 245 |
246 } // namespace base | 246 } // namespace base |
OLD | NEW |