| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 time_t File::LastModified(const char* name) { | 189 time_t File::LastModified(const char* name) { |
| 190 struct stat st; | 190 struct stat st; |
| 191 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 191 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 192 return st.st_mtime; | 192 return st.st_mtime; |
| 193 } | 193 } |
| 194 return -1; | 194 return -1; |
| 195 } | 195 } |
| 196 | 196 |
| 197 | 197 |
| 198 char* File::LinkTarget(const char* pathname) { |
| 199 struct stat link_stats; |
| 200 if (lstat(pathname, &link_stats) != 0) return NULL; |
| 201 // TODO(whesse): return a better error than LinkIOException(OSError) here. |
| 202 if (!S_ISLNK(link_stats.st_mode)) return NULL; |
| 203 size_t target_size = link_stats.st_size; |
| 204 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); |
| 205 size_t read_size = readlink(pathname, target_name, target_size + 1); |
| 206 if (read_size != target_size) { |
| 207 free(target_name); |
| 208 return NULL; |
| 209 } |
| 210 target_name[target_size] = '\0'; |
| 211 return target_name; |
| 212 } |
| 213 |
| 214 |
| 198 bool File::IsAbsolutePath(const char* pathname) { | 215 bool File::IsAbsolutePath(const char* pathname) { |
| 199 return (pathname != NULL && pathname[0] == '/'); | 216 return (pathname != NULL && pathname[0] == '/'); |
| 200 } | 217 } |
| 201 | 218 |
| 202 | 219 |
| 203 char* File::GetCanonicalPath(const char* pathname) { | 220 char* File::GetCanonicalPath(const char* pathname) { |
| 204 char* abs_path = NULL; | 221 char* abs_path = NULL; |
| 205 if (pathname != NULL) { | 222 if (pathname != NULL) { |
| 206 // On some older MacOs versions the default behaviour of realpath allocating | 223 // On some older MacOs versions the default behaviour of realpath allocating |
| 207 // space for the resolved_path when a NULL is passed in does not seem to | 224 // space for the resolved_path when a NULL is passed in does not seem to |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); | 288 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); |
| 272 } | 289 } |
| 273 if (stat_success == -1) return File::kDoesNotExist; | 290 if (stat_success == -1) return File::kDoesNotExist; |
| 274 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; | 291 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; |
| 275 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; | 292 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; |
| 276 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; | 293 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; |
| 277 return File::kDoesNotExist; | 294 return File::kDoesNotExist; |
| 278 } | 295 } |
| 279 | 296 |
| 280 #endif // defined(TARGET_OS_MACOS) | 297 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |