| 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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 *error = PLATFORM_FILE_ERROR_FAILED; | 74 *error = PLATFORM_FILE_ERROR_FAILED; |
| 75 return kInvalidPlatformFileValue; | 75 return kInvalidPlatformFileValue; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) { | 78 if (flags & PLATFORM_FILE_WRITE && flags & PLATFORM_FILE_READ) { |
| 79 open_flags |= O_RDWR; | 79 open_flags |= O_RDWR; |
| 80 } else if (flags & PLATFORM_FILE_WRITE) { | 80 } else if (flags & PLATFORM_FILE_WRITE) { |
| 81 open_flags |= O_WRONLY; | 81 open_flags |= O_WRONLY; |
| 82 } else if (!(flags & PLATFORM_FILE_READ) && | 82 } else if (!(flags & PLATFORM_FILE_READ) && |
| 83 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && | 83 !(flags & PLATFORM_FILE_WRITE_ATTRIBUTES) && |
| 84 !(flags & PLATFORM_FILE_APPEND) && |
| 84 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { | 85 !(flags & PLATFORM_FILE_OPEN_ALWAYS)) { |
| 85 NOTREACHED(); | 86 NOTREACHED(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 if (flags & PLATFORM_FILE_TERMINAL_DEVICE) | 89 if (flags & PLATFORM_FILE_TERMINAL_DEVICE) |
| 89 open_flags |= O_NOCTTY | O_NDELAY; | 90 open_flags |= O_NOCTTY | O_NDELAY; |
| 90 | 91 |
| 92 if (flags & PLATFORM_FILE_APPEND && flags & PLATFORM_FILE_READ) |
| 93 open_flags |= O_APPEND | O_RDWR; |
| 94 else if (flags & PLATFORM_FILE_APPEND) |
| 95 open_flags |= O_APPEND | O_WRONLY; |
| 96 |
| 91 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); | 97 COMPILE_ASSERT(O_RDONLY == 0, O_RDONLY_must_equal_zero); |
| 92 | 98 |
| 93 int mode = S_IRUSR | S_IWUSR; | 99 int mode = S_IRUSR | S_IWUSR; |
| 94 #if defined(OS_CHROMEOS) | 100 #if defined(OS_CHROMEOS) |
| 95 mode |= S_IRGRP | S_IROTH; | 101 mode |= S_IRGRP | S_IROTH; |
| 96 #endif | 102 #endif |
| 97 | 103 |
| 98 int descriptor = | 104 int descriptor = |
| 99 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); | 105 HANDLE_EINTR(open(name.value().c_str(), open_flags, mode)); |
| 100 | 106 |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 default: | 335 default: |
| 330 #if !defined(OS_NACL) // NaCl build has no metrics code. | 336 #if !defined(OS_NACL) // NaCl build has no metrics code. |
| 331 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", | 337 UMA_HISTOGRAM_SPARSE_SLOWLY("PlatformFile.UnknownErrors.Posix", |
| 332 saved_errno); | 338 saved_errno); |
| 333 #endif | 339 #endif |
| 334 return PLATFORM_FILE_ERROR_FAILED; | 340 return PLATFORM_FILE_ERROR_FAILED; |
| 335 } | 341 } |
| 336 } | 342 } |
| 337 | 343 |
| 338 } // namespace base | 344 } // namespace base |
| OLD | NEW |