Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: runtime/bin/file_linux.cc

Issue 12812010: dart:io | Add Link.targetSync on all platforms. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Improve error handling on Windows. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 // TODO(whesse): return a better error than LinkIOException(OSError) here.
200 if (!S_ISLNK(link_stats.st_mode)) return NULL;
201 size_t target_size = link_stats.st_size;
202 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1));
203 size_t read_size = readlink(pathname, target_name, target_size + 1);
204 if (read_size != target_size) {
205 free(target_name);
206 return NULL;
207 }
208 target_name[target_size] = '\0';
209 return target_name;
210 }
211
212
196 bool File::IsAbsolutePath(const char* pathname) { 213 bool File::IsAbsolutePath(const char* pathname) {
197 return (pathname != NULL && pathname[0] == '/'); 214 return (pathname != NULL && pathname[0] == '/');
198 } 215 }
199 216
200 217
201 char* File::GetCanonicalPath(const char* pathname) { 218 char* File::GetCanonicalPath(const char* pathname) {
202 char* abs_path = NULL; 219 char* abs_path = NULL;
203 if (pathname != NULL) { 220 if (pathname != NULL) {
204 do { 221 do {
205 abs_path = realpath(pathname, NULL); 222 abs_path = realpath(pathname, NULL);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); 280 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info));
264 } 281 }
265 if (stat_success == -1) return File::kDoesNotExist; 282 if (stat_success == -1) return File::kDoesNotExist;
266 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; 283 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
267 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; 284 if (S_ISREG(entry_info.st_mode)) return File::kIsFile;
268 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; 285 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink;
269 return File::kDoesNotExist; 286 return File::kDoesNotExist;
270 } 287 }
271 288
272 #endif // defined(TARGET_OS_LINUX) 289 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/bin/file_android.cc ('k') | runtime/bin/file_macos.cc » ('j') | runtime/bin/file_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698