Skip to content

Instantly share code, notes, and snippets.

@wader
Created November 11, 2012 20:05
Show Gist options
  • Save wader/4056077 to your computer and use it in GitHub Desktop.
Save wader/4056077 to your computer and use it in GitHub Desktop.
-[NSString stringByResolvingCanonicalPath]
@interface NSString (stringByResolvingCanonicalPath)
- (NSString *)stringByResolvingCanonicalPath;
@end
@implementation NSString (stringByResolvingCanonicalPath)
- (NSString *)stringByResolvingCanonicalPath {
FSRef fsRef;
if (FSPathMakeRef((UInt8 const *)[self UTF8String], &fsRef, NULL) != 0) {
return nil;
}
char *path = malloc(PATH_MAX);
if (FSRefMakePath(&fsRef, (UInt8 *)path, PATH_MAX) != 0) {
free(path);
return nil;
}
NSString *canonicalPath = [NSString stringWithUTF8String:path];
free(path);
return canonicalPath;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment