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

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: Fix memory leak. Improve OS error for Link.target of a non-link. 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 if (!S_ISLNK(link_stats.st_mode)) {
199 errno = ENOENT;
200 return NULL;
201 }
202 size_t target_size = link_stats.st_size;
203 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1));
204 size_t read_size = readlink(pathname, target_name, target_size + 1);
205 if (read_size != target_size) {
206 free(target_name);
207 return NULL;
208 }
209 target_name[target_size] = '\0';
210 return target_name;
211 }
212
213
195 bool File::IsAbsolutePath(const char* pathname) { 214 bool File::IsAbsolutePath(const char* pathname) {
196 return (pathname != NULL && pathname[0] == '/'); 215 return (pathname != NULL && pathname[0] == '/');
197 } 216 }
198 217
199 218
200 char* File::GetCanonicalPath(const char* pathname) { 219 char* File::GetCanonicalPath(const char* pathname) {
201 char* abs_path = NULL; 220 char* abs_path = NULL;
202 if (pathname != NULL) { 221 if (pathname != NULL) {
203 do { 222 do {
204 abs_path = realpath(pathname, NULL); 223 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)); 281 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info));
263 } 282 }
264 if (stat_success == -1) return File::kDoesNotExist; 283 if (stat_success == -1) return File::kDoesNotExist;
265 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; 284 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
266 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; 285 if (S_ISREG(entry_info.st_mode)) return File::kIsFile;
267 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; 286 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink;
268 return File::kDoesNotExist; 287 return File::kDoesNotExist;
269 } 288 }
270 289
271 #endif // defined(TARGET_OS_ANDROID) 290 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/bin/file.cc ('k') | runtime/bin/file_linux.cc » ('j') | runtime/bin/file_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698