| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 time_t File::LastModified(const char* name) { | 187 time_t File::LastModified(const char* name) { |
| 188 struct stat st; | 188 struct stat st; |
| 189 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { | 189 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { |
| 190 return st.st_mtime; | 190 return st.st_mtime; |
| 191 } | 191 } |
| 192 return -1; | 192 return -1; |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 char* File::LinkTarget(const char* pathname) { |
| 197 struct stat link_stats; |
| 198 if (lstat(pathname, &link_stats) != 0) return NULL; |
| 199 if (!S_ISLNK(link_stats.st_mode)) { |
| 200 errno = ENOENT; |
| 201 return NULL; |
| 202 } |
| 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 |
| 196 bool File::IsAbsolutePath(const char* pathname) { | 215 bool File::IsAbsolutePath(const char* pathname) { |
| 197 return (pathname != NULL && pathname[0] == '/'); | 216 return (pathname != NULL && pathname[0] == '/'); |
| 198 } | 217 } |
| 199 | 218 |
| 200 | 219 |
| 201 char* File::GetCanonicalPath(const char* pathname) { | 220 char* File::GetCanonicalPath(const char* pathname) { |
| 202 char* abs_path = NULL; | 221 char* abs_path = NULL; |
| 203 if (pathname != NULL) { | 222 if (pathname != NULL) { |
| 204 do { | 223 do { |
| 205 abs_path = realpath(pathname, NULL); | 224 abs_path = realpath(pathname, NULL); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); | 282 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); |
| 264 } | 283 } |
| 265 if (stat_success == -1) return File::kDoesNotExist; | 284 if (stat_success == -1) return File::kDoesNotExist; |
| 266 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; | 285 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; |
| 267 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; | 286 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; |
| 268 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; | 287 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; |
| 269 return File::kDoesNotExist; | 288 return File::kDoesNotExist; |
| 270 } | 289 } |
| 271 | 290 |
| 272 #endif // defined(TARGET_OS_LINUX) | 291 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |