| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return st.st_size; | 102 return st.st_size; |
| 103 } | 103 } |
| 104 return -1; | 104 return -1; |
| 105 } | 105 } |
| 106 | 106 |
| 107 | 107 |
| 108 File* File::Open(const char* name, FileOpenMode mode) { | 108 File* File::Open(const char* name, FileOpenMode mode) { |
| 109 // Report errors for non-regular files. | 109 // Report errors for non-regular files. |
| 110 struct stat st; | 110 struct stat st; |
| 111 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 111 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 112 if (!S_ISREG(st.st_mode)) { | 112 // Only accept regular files and character devices. |
| 113 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { |
| 113 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 114 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
| 114 return NULL; | 115 return NULL; |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 int flags = O_RDONLY; | 118 int flags = O_RDONLY; |
| 118 if ((mode & kWrite) != 0) { | 119 if ((mode & kWrite) != 0) { |
| 119 flags = (O_RDWR | O_CREAT); | 120 flags = (O_RDWR | O_CREAT); |
| 120 } | 121 } |
| 121 if ((mode & kTruncate) != 0) { | 122 if ((mode & kTruncate) != 0) { |
| 122 flags = flags | O_TRUNC; | 123 flags = flags | O_TRUNC; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); | 265 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); |
| 265 } | 266 } |
| 266 if (stat_success == -1) return File::kDoesNotExist; | 267 if (stat_success == -1) return File::kDoesNotExist; |
| 267 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; | 268 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; |
| 268 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; | 269 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; |
| 269 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; | 270 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; |
| 270 return File::kDoesNotExist; | 271 return File::kDoesNotExist; |
| 271 } | 272 } |
| 272 | 273 |
| 273 #endif // defined(TARGET_OS_MACOS) | 274 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |