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/files/file.h" | 5 #include "base/files/file.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
10 #include <unistd.h> | 10 #include <unistd.h> |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 if (flags & FLAG_OPEN_TRUNCATED) { | 141 if (flags & FLAG_OPEN_TRUNCATED) { |
142 DCHECK(!open_flags); | 142 DCHECK(!open_flags); |
143 DCHECK(flags & FLAG_WRITE); | 143 DCHECK(flags & FLAG_WRITE); |
144 open_flags = O_TRUNC; | 144 open_flags = O_TRUNC; |
145 } | 145 } |
146 | 146 |
147 if (!open_flags && !(flags & FLAG_OPEN) && !(flags & FLAG_OPEN_ALWAYS)) { | 147 if (!open_flags && !(flags & FLAG_OPEN) && !(flags & FLAG_OPEN_ALWAYS)) { |
148 NOTREACHED(); | 148 NOTREACHED(); |
149 errno = EOPNOTSUPP; | 149 errno = EOPNOTSUPP; |
150 error_ = FILE_ERROR_FAILED; | 150 error_details_ = FILE_ERROR_FAILED; |
151 return; | 151 return; |
152 } | 152 } |
153 | 153 |
154 if (flags & FLAG_WRITE && flags & FLAG_READ) { | 154 if (flags & FLAG_WRITE && flags & FLAG_READ) { |
155 open_flags |= O_RDWR; | 155 open_flags |= O_RDWR; |
156 } else if (flags & FLAG_WRITE) { | 156 } else if (flags & FLAG_WRITE) { |
157 open_flags |= O_WRONLY; | 157 open_flags |= O_WRONLY; |
158 } else if (!(flags & FLAG_READ) && | 158 } else if (!(flags & FLAG_READ) && |
159 !(flags & FLAG_WRITE_ATTRIBUTES) && | 159 !(flags & FLAG_WRITE_ATTRIBUTES) && |
160 !(flags & FLAG_APPEND) && | 160 !(flags & FLAG_APPEND) && |
(...skipping 30 matching lines...) Expand all Loading... |
191 } | 191 } |
192 } | 192 } |
193 | 193 |
194 if (descriptor >= 0 && (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE))) | 194 if (descriptor >= 0 && (flags & (FLAG_CREATE_ALWAYS | FLAG_CREATE))) |
195 created_ = true; | 195 created_ = true; |
196 | 196 |
197 if ((descriptor >= 0) && (flags & FLAG_DELETE_ON_CLOSE)) | 197 if ((descriptor >= 0) && (flags & FLAG_DELETE_ON_CLOSE)) |
198 unlink(name.value().c_str()); | 198 unlink(name.value().c_str()); |
199 | 199 |
200 if (descriptor >= 0) | 200 if (descriptor >= 0) |
201 error_ = FILE_OK; | 201 error_details_ = FILE_OK; |
202 else | 202 else |
203 error_ = File::OSErrorToFileError(errno); | 203 error_details_ = File::OSErrorToFileError(errno); |
204 | 204 |
205 file_ = descriptor; | 205 file_ = descriptor; |
206 } | 206 } |
207 #endif // !defined(OS_NACL) | 207 #endif // !defined(OS_NACL) |
208 | 208 |
209 bool File::IsValid() const { | 209 bool File::IsValid() const { |
210 return file_ >= 0; | 210 return file_ >= 0; |
211 } | 211 } |
212 | 212 |
213 PlatformFile File::TakePlatformFile() { | 213 PlatformFile File::TakePlatformFile() { |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 return FILE_ERROR_FAILED; | 471 return FILE_ERROR_FAILED; |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 void File::SetPlatformFile(PlatformFile file) { | 475 void File::SetPlatformFile(PlatformFile file) { |
476 DCHECK_EQ(file_, kInvalidPlatformFileValue); | 476 DCHECK_EQ(file_, kInvalidPlatformFileValue); |
477 file_ = file; | 477 file_ = file; |
478 } | 478 } |
479 | 479 |
480 } // namespace base | 480 } // namespace base |
OLD | NEW |