| 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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 } | 322 } |
| 323 | 323 |
| 324 | 324 |
| 325 char* File::LinkTarget(const char* pathname) { | 325 char* File::LinkTarget(const char* pathname) { |
| 326 struct stat link_stats; | 326 struct stat link_stats; |
| 327 if (lstat(pathname, &link_stats) != 0) return NULL; | 327 if (lstat(pathname, &link_stats) != 0) return NULL; |
| 328 if (!S_ISLNK(link_stats.st_mode)) { | 328 if (!S_ISLNK(link_stats.st_mode)) { |
| 329 errno = ENOENT; | 329 errno = ENOENT; |
| 330 return NULL; | 330 return NULL; |
| 331 } | 331 } |
| 332 size_t target_size = link_stats.st_size; | 332 // Don't rely on the link_stats.st_size for the size of the link |
| 333 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); | 333 // target. The link might have changed before the readlink call. |
| 334 size_t read_size = readlink(pathname, target_name, target_size + 1); | 334 const int kBufferSize = 1024; |
| 335 if (read_size != target_size) { | 335 char target[kBufferSize]; |
| 336 free(target_name); | 336 size_t target_size = TEMP_FAILURE_RETRY( |
| 337 readlink(pathname, target, kBufferSize)); |
| 338 if (target_size <= 0) { |
| 337 return NULL; | 339 return NULL; |
| 338 } | 340 } |
| 341 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1)); |
| 342 if (target_name == NULL) { |
| 343 return NULL |
| 344 } |
| 345 memmove(target_name, target, target_size); |
| 339 target_name[target_size] = '\0'; | 346 target_name[target_size] = '\0'; |
| 340 return target_name; | 347 return target_name; |
| 341 } | 348 } |
| 342 | 349 |
| 343 | 350 |
| 344 bool File::IsAbsolutePath(const char* pathname) { | 351 bool File::IsAbsolutePath(const char* pathname) { |
| 345 return (pathname != NULL && pathname[0] == '/'); | 352 return (pathname != NULL && pathname[0] == '/'); |
| 346 } | 353 } |
| 347 | 354 |
| 348 | 355 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 return (file_1_info.st_ino == file_2_info.st_ino && | 425 return (file_1_info.st_ino == file_2_info.st_ino && |
| 419 file_1_info.st_dev == file_2_info.st_dev) ? | 426 file_1_info.st_dev == file_2_info.st_dev) ? |
| 420 File::kIdentical : | 427 File::kIdentical : |
| 421 File::kDifferent; | 428 File::kDifferent; |
| 422 } | 429 } |
| 423 | 430 |
| 424 } // namespace bin | 431 } // namespace bin |
| 425 } // namespace dart | 432 } // namespace dart |
| 426 | 433 |
| 427 #endif // defined(TARGET_OS_MACOS) | 434 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |