| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return st.st_size; | 100 return st.st_size; |
| 101 } | 101 } |
| 102 return -1; | 102 return -1; |
| 103 } | 103 } |
| 104 | 104 |
| 105 | 105 |
| 106 File* File::Open(const char* name, FileOpenMode mode) { | 106 File* File::Open(const char* name, FileOpenMode mode) { |
| 107 // Report errors for non-regular files. | 107 // Report errors for non-regular files. |
| 108 struct stat st; | 108 struct stat st; |
| 109 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 109 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 110 if (!S_ISREG(st.st_mode)) { | 110 // Only accept regular files and character devices. |
| 111 if (!S_ISREG(st.st_mode) && !S_ISCHR(st.st_mode)) { |
| 111 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; | 112 errno = (S_ISDIR(st.st_mode)) ? EISDIR : ENOENT; |
| 112 return NULL; | 113 return NULL; |
| 113 } | 114 } |
| 114 } | 115 } |
| 115 int flags = O_RDONLY; | 116 int flags = O_RDONLY; |
| 116 if ((mode & kWrite) != 0) { | 117 if ((mode & kWrite) != 0) { |
| 117 flags = (O_RDWR | O_CREAT); | 118 flags = (O_RDWR | O_CREAT); |
| 118 } | 119 } |
| 119 if ((mode & kTruncate) != 0) { | 120 if ((mode & kTruncate) != 0) { |
| 120 flags = flags | O_TRUNC; | 121 flags = flags | O_TRUNC; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); | 257 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); |
| 257 } | 258 } |
| 258 if (stat_success == -1) return File::kDoesNotExist; | 259 if (stat_success == -1) return File::kDoesNotExist; |
| 259 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; | 260 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; |
| 260 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; | 261 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; |
| 261 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; | 262 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; |
| 262 return File::kDoesNotExist; | 263 return File::kDoesNotExist; |
| 263 } | 264 } |
| 264 | 265 |
| 265 #endif // defined(TARGET_OS_LINUX) | 266 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |