Created
November 11, 2012 20:05
-
-
Save wader/4056077 to your computer and use it in GitHub Desktop.
-[NSString stringByResolvingCanonicalPath]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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