1 //IconFamily depends heavily upon Carbon calls and thus will only work in Mac OS X
2 #ifdef MAC_OS_X_VERSION_10_0
4 #import "NSString+CarbonFSSpecCreation.h"
6 @implementation NSString (CarbonFSSpecCreation)
8 - (BOOL) getFSRef:(FSRef*)fsRef createFileIfNecessary:(BOOL)createFile
10 NSFileManager* fileManager = [NSFileManager defaultManager];
14 // Check whether the file exists already. If not, create an empty file if requested.
15 if (![fileManager fileExistsAtPath:self]) {
17 if (![@"" writeToFile:self atomically:YES]) {
25 // Create a CFURL with the specified POSIX path.
26 urlRef = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
29 FALSE /* isDirectory */ );
31 // printf( "** Couldn't make a CFURLRef for the file.\n" );
35 // Try to create an FSRef from the URL. (If the specified file doesn't exist, this
36 // function will return false, but if we've reached this code we've already insured
37 // that the file exists.)
38 gotFSRef = CFURLGetFSRef( urlRef, fsRef );
42 // printf( "** Couldn't get an FSRef for the file.\n" );
49 - (BOOL) getFSSpec:(FSSpec*)fsSpec createFileIfNecessary:(BOOL)createFile
53 if (![self getFSRef:&fsRef createFileIfNecessary:createFile])
56 if (FSGetCatalogInfo( &fsRef,
62 // printf( "** Couldn't get an FSSpec for the file.\n" );
69 + (NSString *)pathForFSRef:(FSRef *)object
71 NSString *path = NULL;
73 UInt8 *pathbuf = malloc(PATH_MAX);
74 if (pathbuf != NULL) {
75 OSStatus err = FSRefMakePath(object, pathbuf, PATH_MAX);
78 path = [(NSString *)CFStringCreateWithCString(kCFAllocatorDefault, (char *)pathbuf, kCFStringEncodingUTF8) autorelease];