Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: base/platform_file_posix.cc

Issue 7038032: Fix PP_FileOpenFlags_Dev handling: (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 10
(...skipping 26 matching lines...) Expand all
37 open_flags = O_CREAT | O_EXCL; 37 open_flags = O_CREAT | O_EXCL;
38 38
39 if (created) 39 if (created)
40 *created = false; 40 *created = false;
41 41
42 if (flags & PLATFORM_FILE_CREATE_ALWAYS) { 42 if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
43 DCHECK(!open_flags); 43 DCHECK(!open_flags);
44 open_flags = O_CREAT | O_TRUNC; 44 open_flags = O_CREAT | O_TRUNC;
45 } 45 }
46 46
47 if (flags & PLATFORM_FILE_OPEN_TRUNCATED) {
48 DCHECK(!open_flags);
49 DCHECK(flags & PLATFORM_FILE_WRITE);
50 open_flags = O_TRUNC;
51 }
52
47 if (!open_flags && !(flags & PLATFORM_FILE_OPEN) && 53 if (!open_flags && !(flags & PLATFORM_FILE_OPEN) &&
48 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { 54 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
49 NOTREACHED(); 55 NOTREACHED();
50 errno = EOPNOTSUPP; 56 errno = EOPNOTSUPP;
51 *error_code = error_code ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK; 57 *error_code = error_code ? PLATFORM_FILE_ERROR_FAILED : PLATFORM_FILE_OK;
52 return kInvalidPlatformFileValue; 58 return kInvalidPlatformFileValue;
53 } 59 }
54 60
55 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) { 61 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) {
56 open_flags |= O_RDWR; 62 open_flags |= O_RDWR;
57 } else if (flags & PLATFORM_FILE_WRITE) { 63 } else if (flags & PLATFORM_FILE_WRITE) {
58 open_flags |= O_WRONLY; 64 open_flags |= O_WRONLY;
59 } else if (!(flags & PLATFORM_FILE_READ) && 65 } else if (!(flags & PLATFORM_FILE_READ) &&
60 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && 66 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) &&
61 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { 67 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
62 NOTREACHED(); 68 NOTREACHED();
63 } 69 }
64 70
65 if (flags & PLATFORM_FILE_TRUNCATE) {
66 DCHECK(flags & PLATFORM_FILE_WRITE);
67 open_flags |= O_TRUNC;
68 }
69
70 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); 71 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero);
71 72
72 int descriptor = 73 int descriptor =
73 HANDLE_EINTR(open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR)); 74 HANDLE_EINTR(open(name.value().c_str(), open_flags, S_IRUSR | S_IWUSR));
74 75
75 if (flags & PLATFORM_FILE_OPEN_ALWAYS) { 76 if (flags & PLATFORM_FILE_OPEN_ALWAYS) {
76 if (descriptor <= 0) { 77 if (descriptor <= 0) {
77 open_flags |= O_CREAT; 78 open_flags |= O_CREAT;
78 if (flags & PLATFORM_FILE_EXCLUSIVE_READ || 79 if (flags & PLATFORM_FILE_EXCLUSIVE_READ ||
79 flags & PLATFORM_FILE_EXCLUSIVE_WRITE) { 80 flags & PLATFORM_FILE_EXCLUSIVE_WRITE) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 info->is_directory = S_ISDIR(file_info.st_mode); 185 info->is_directory = S_ISDIR(file_info.st_mode);
185 info->is_symbolic_link = S_ISLNK(file_info.st_mode); 186 info->is_symbolic_link = S_ISLNK(file_info.st_mode);
186 info->size = file_info.st_size; 187 info->size = file_info.st_size;
187 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); 188 info->last_modified = base::Time::FromTimeT(file_info.st_mtime);
188 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); 189 info->last_accessed = base::Time::FromTimeT(file_info.st_atime);
189 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); 190 info->creation_time = base::Time::FromTimeT(file_info.st_ctime);
190 return true; 191 return true;
191 } 192 }
192 193
193 } // namespace base 194 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file.h ('k') | base/platform_file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698