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

Side by Side Diff: runtime/bin/file_macos.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_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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 time_t File::LastModified(const char* name) { 189 time_t File::LastModified(const char* name) {
190 struct stat st; 190 struct stat st;
191 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) { 191 if (TEMP_FAILURE_RETRY(stat(name, &st)) == 0) {
192 return st.st_mtime; 192 return st.st_mtime;
193 } 193 }
194 return -1; 194 return -1;
195 } 195 }
196 196
197 197
198 char* File::LinkTarget(const char* pathname) {
199 struct stat link_stats;
200 if (lstat(pathname, &link_stats) != 0) return NULL;
201 if (!S_ISLNK(link_stats.st_mode)) {
202 errno = ENOENT;
203 return NULL;
204 }
205 size_t target_size = link_stats.st_size;
206 char* target_name = reinterpret_cast<char*>(malloc(target_size + 1));
207 size_t read_size = readlink(pathname, target_name, target_size + 1);
208 if (read_size != target_size) {
209 free(target_name);
210 return NULL;
211 }
212 target_name[target_size] = '\0';
213 return target_name;
214 }
215
216
198 bool File::IsAbsolutePath(const char* pathname) { 217 bool File::IsAbsolutePath(const char* pathname) {
199 return (pathname != NULL && pathname[0] == '/'); 218 return (pathname != NULL && pathname[0] == '/');
200 } 219 }
201 220
202 221
203 char* File::GetCanonicalPath(const char* pathname) { 222 char* File::GetCanonicalPath(const char* pathname) {
204 char* abs_path = NULL; 223 char* abs_path = NULL;
205 if (pathname != NULL) { 224 if (pathname != NULL) {
206 // On some older MacOs versions the default behaviour of realpath allocating 225 // On some older MacOs versions the default behaviour of realpath allocating
207 // space for the resolved_path when a NULL is passed in does not seem to 226 // space for the resolved_path when a NULL is passed in does not seem to
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info)); 290 stat_success = TEMP_FAILURE_RETRY(lstat(pathname, &entry_info));
272 } 291 }
273 if (stat_success == -1) return File::kDoesNotExist; 292 if (stat_success == -1) return File::kDoesNotExist;
274 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory; 293 if (S_ISDIR(entry_info.st_mode)) return File::kIsDirectory;
275 if (S_ISREG(entry_info.st_mode)) return File::kIsFile; 294 if (S_ISREG(entry_info.st_mode)) return File::kIsFile;
276 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink; 295 if (S_ISLNK(entry_info.st_mode)) return File::kIsLink;
277 return File::kDoesNotExist; 296 return File::kDoesNotExist;
278 } 297 }
279 298
280 #endif // defined(TARGET_OS_MACOS) 299 #endif // defined(TARGET_OS_MACOS)
OLDNEW
« no previous file with comments | « runtime/bin/file_linux.cc ('k') | runtime/bin/file_patch.dart » ('j') | runtime/bin/file_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698