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

Side by Side Diff: runtime/bin/file_android.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 copying of target string 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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 185
186 time_t File::LastModified(const char* name) { 186 time_t File::LastModified(const char* name) {
187 struct stat st; 187 struct stat st;
188 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 188 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
189 return st.st_mtime; 189 return st.st_mtime;
190 } 190 }
191 return -1; 191 return -1;
192 } 192 }
193 193
194 194
195 char* File::LinkTarget(const char* pathname) {
196 struct stat link_stats;
197 if (lstat(pathname, &link_stats) != 0) return NULL;
198 // TODO(whesse): return a better error than LinkIOException(OSError) here.
199 if (!S_ISLNK(link_stats.st_mode)) return NULL;
200 size_t target_size = link_stats.st_size;
201 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1));
202 size_t read_size = readlink(pathname, target_name, target_size + 1);
203 if (read_size != target_size) {
204 free(target_name);
205 return NULL;
206 }
207 target_name[target_size] = '\0';
208 return target_name;
209 }
210
211
195 bool File::IsAbsolutePath(const char* pathname) { 212 bool File::IsAbsolutePath(const char* pathname) {
196 return (pathname != NULL && pathname[0] == '/'); 213 return (pathname != NULL && pathname[0] == '/');
197 } 214 }
198 215
199 216
200 char* File::GetCanonicalPath(const char* pathname) { 217 char* File::GetCanonicalPath(const char* pathname) {
201 char* abs_path = NULL; 218 char* abs_path = NULL;
202 if (pathname != NULL) { 219 if (pathname != NULL) {
203 do { 220 do {
204 abs_path = realpath(pathname, NULL); 221 abs_path = realpath(pathname, NULL);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); 279 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info));
263 } 280 }
264 if (stat_success == -1) return File::kDoesNotExist; 281 if (stat_success == -1) return File::kDoesNotExist;
265 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; 282 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
266 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; 283 if (S_ISREG(entry_info.st_mode)) return File::kIsFile;
267 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; 284 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink;
268 return File::kDoesNotExist; 285 return File::kDoesNotExist;
269 } 286 }
270 287
271 #endif // defined(TARGET_OS_ANDROID) 288 #endif // defined(TARGET_OS_ANDROID)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698