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

Side by Side Diff: base/platform_file_posix.cc

Issue 12095045: Merge 175642 (also includes 175980) (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1364/src/
Patch Set: Created 7 years, 10 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.cc ('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) 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/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 23 matching lines...) Expand all
34 } 34 }
35 #else 35 #else
36 typedef struct stat64 stat_wrapper_t; 36 typedef struct stat64 stat_wrapper_t;
37 static int CallFstat(int fd, stat_wrapper_t *sb) { 37 static int CallFstat(int fd, stat_wrapper_t *sb) {
38 base::ThreadRestrictions::AssertIOAllowed(); 38 base::ThreadRestrictions::AssertIOAllowed();
39 return fstat64(fd, sb); 39 return fstat64(fd, sb);
40 } 40 }
41 #endif 41 #endif
42 42
43 // TODO(erikkay): does it make sense to support PLATFORM_FILE_EXCLUSIVE_* here? 43 // TODO(erikkay): does it make sense to support PLATFORM_FILE_EXCLUSIVE_* here?
44 PlatformFile CreatePlatformFile(const FilePath& name, int flags, 44 PlatformFile CreatePlatformFileUnsafe(const FilePath& name,
45 bool* created, PlatformFileError* error_code) { 45 int flags,
46 bool* created,
47 PlatformFileError* error) {
46 base::ThreadRestrictions::AssertIOAllowed(); 48 base::ThreadRestrictions::AssertIOAllowed();
47 49
48 int open_flags = 0; 50 int open_flags = 0;
49 if (flags & PLATFORM_FILE_CREATE) 51 if (flags & PLATFORM_FILE_CREATE)
50 open_flags = O_CREAT | O_EXCL; 52 open_flags = O_CREAT | O_EXCL;
51 53
52 if (created) 54 if (created)
53 *created = false; 55 *created = false;
54 56
55 if (flags & PLATFORM_FILE_CREATE_ALWAYS) { 57 if (flags & PLATFORM_FILE_CREATE_ALWAYS) {
56 DCHECK(!open_flags); 58 DCHECK(!open_flags);
57 open_flags = O_CREAT | O_TRUNC; 59 open_flags = O_CREAT | O_TRUNC;
58 } 60 }
59 61
60 if (flags & PLATFORM_FILE_OPEN_TRUNCATED) { 62 if (flags & PLATFORM_FILE_OPEN_TRUNCATED) {
61 DCHECK(!open_flags); 63 DCHECK(!open_flags);
62 DCHECK(flags & PLATFORM_FILE_WRITE); 64 DCHECK(flags & PLATFORM_FILE_WRITE);
63 open_flags = O_TRUNC; 65 open_flags = O_TRUNC;
64 } 66 }
65 67
66 if (!open_flags && !(flags & PLATFORM_FILE_OPEN) && 68 if (!open_flags && !(flags & PLATFORM_FILE_OPEN) &&
67 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { 69 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
68 NOTREACHED(); 70 NOTREACHED();
69 errno = EOPNOTSUPP; 71 errno = EOPNOTSUPP;
70 if (error_code) 72 if (error)
71 *error_code = PLATFORM_FILE_ERROR_FAILED; 73 *error = PLATFORM_FILE_ERROR_FAILED;
72 return kInvalidPlatformFileValue; 74 return kInvalidPlatformFileValue;
73 } 75 }
74 76
75 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) { 77 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) {
76 open_flags |= O_RDWR; 78 open_flags |= O_RDWR;
77 } else if (flags & PLATFORM_FILE_WRITE) { 79 } else if (flags & PLATFORM_FILE_WRITE) {
78 open_flags |= O_WRONLY; 80 open_flags |= O_WRONLY;
79 } else if (!(flags & PLATFORM_FILE_READ) && 81 } else if (!(flags & PLATFORM_FILE_READ) &&
80 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && 82 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) &&
81 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { 83 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) {
(...skipping 28 matching lines...) Expand all
110 } 112 }
111 113
112 if (created && (descriptor >= 0) && 114 if (created && (descriptor >= 0) &&
113 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE))) 115 (flags & (PLATFORM_FILE_CREATE_ALWAYS | PLATFORM_FILE_CREATE)))
114 *created = true; 116 *created = true;
115 117
116 if ((descriptor >= 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) { 118 if ((descriptor >= 0) && (flags & PLATFORM_FILE_DELETE_ON_CLOSE)) {
117 unlink(name.value().c_str()); 119 unlink(name.value().c_str());
118 } 120 }
119 121
120 if (error_code) { 122 if (error) {
121 if (descriptor >= 0) 123 if (descriptor >= 0)
122 *error_code = PLATFORM_FILE_OK; 124 *error = PLATFORM_FILE_OK;
123 else { 125 else {
124 switch (errno) { 126 switch (errno) {
125 case EACCES: 127 case EACCES:
126 case EISDIR: 128 case EISDIR:
127 case EROFS: 129 case EROFS:
128 case EPERM: 130 case EPERM:
129 *error_code = PLATFORM_FILE_ERROR_ACCESS_DENIED; 131 *error = PLATFORM_FILE_ERROR_ACCESS_DENIED;
130 break; 132 break;
131 case ETXTBSY: 133 case ETXTBSY:
132 *error_code = PLATFORM_FILE_ERROR_IN_USE; 134 *error = PLATFORM_FILE_ERROR_IN_USE;
133 break; 135 break;
134 case EEXIST: 136 case EEXIST:
135 *error_code = PLATFORM_FILE_ERROR_EXISTS; 137 *error = PLATFORM_FILE_ERROR_EXISTS;
136 break; 138 break;
137 case ENOENT: 139 case ENOENT:
138 *error_code = PLATFORM_FILE_ERROR_NOT_FOUND; 140 *error = PLATFORM_FILE_ERROR_NOT_FOUND;
139 break; 141 break;
140 case EMFILE: 142 case EMFILE:
141 *error_code = PLATFORM_FILE_ERROR_TOO_MANY_OPENED; 143 *error = PLATFORM_FILE_ERROR_TOO_MANY_OPENED;
142 break; 144 break;
143 case ENOMEM: 145 case ENOMEM:
144 *error_code = PLATFORM_FILE_ERROR_NO_MEMORY; 146 *error = PLATFORM_FILE_ERROR_NO_MEMORY;
145 break; 147 break;
146 case ENOSPC: 148 case ENOSPC:
147 *error_code = PLATFORM_FILE_ERROR_NO_SPACE; 149 *error = PLATFORM_FILE_ERROR_NO_SPACE;
148 break; 150 break;
149 case ENOTDIR: 151 case ENOTDIR:
150 *error_code = PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; 152 *error = PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
151 break; 153 break;
152 default: 154 default:
153 *error_code = PLATFORM_FILE_ERROR_FAILED; 155 *error = PLATFORM_FILE_ERROR_FAILED;
154 } 156 }
155 } 157 }
156 } 158 }
157 159
158 return descriptor; 160 return descriptor;
159 } 161 }
160 162
161 bool ClosePlatformFile(PlatformFile file) { 163 bool ClosePlatformFile(PlatformFile file) {
162 base::ThreadRestrictions::AssertIOAllowed(); 164 base::ThreadRestrictions::AssertIOAllowed();
163 return !HANDLE_EINTR(close(file)); 165 return !HANDLE_EINTR(close(file));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 info->is_directory = S_ISDIR(file_info.st_mode); 311 info->is_directory = S_ISDIR(file_info.st_mode);
310 info->is_symbolic_link = S_ISLNK(file_info.st_mode); 312 info->is_symbolic_link = S_ISLNK(file_info.st_mode);
311 info->size = file_info.st_size; 313 info->size = file_info.st_size;
312 info->last_modified = base::Time::FromTimeT(file_info.st_mtime); 314 info->last_modified = base::Time::FromTimeT(file_info.st_mtime);
313 info->last_accessed = base::Time::FromTimeT(file_info.st_atime); 315 info->last_accessed = base::Time::FromTimeT(file_info.st_atime);
314 info->creation_time = base::Time::FromTimeT(file_info.st_ctime); 316 info->creation_time = base::Time::FromTimeT(file_info.st_ctime);
315 return true; 317 return true;
316 } 318 }
317 319
318 } // namespace base 320 } // namespace base
OLDNEW
« no previous file with comments | « base/platform_file.cc ('k') | base/platform_file_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698