41 #include "CAFilePathUtils.h"
44 #if !CA_NO_CORE_SERVICES
45 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
46 #include <CoreServices/CoreServices.h>
48 #include <CoreServices.h>
51 OSStatus PosixPathToParentFSRefAndName(
const char *path, FSRef &outParentDir, CFStringRef &outFileName)
55 CFStringRef cfFullPath = CFStringCreateWithCString(NULL, path, kCFStringEncodingUTF8);
57 CFStringRef cfFullPath = CFStringCreateWithCString(NULL, path, kCFStringEncodingWindowsLatin1);
60 CFURLRef fullurl = CFURLCreateWithFileSystemPath(NULL, cfFullPath, TARGET_OS_WIN32 ? kCFURLWindowsPathStyle : kCFURLPOSIXPathStyle,
false);
61 CFRelease(cfFullPath);
63 CFURLRef dirurl = CFURLCreateCopyDeletingLastPathComponent(NULL, fullurl);
65 OSStatus err = CFURLGetFSRef(dirurl, &outParentDir) ? OSStatus(noErr) : OSStatus(fnfErr);
68 CFStringRef lastPathComponent = CFURLCopyLastPathComponent(fullurl);
70 CFMutableStringRef filename = CFStringCreateMutableCopy(NULL, 0, lastPathComponent);
71 CFRelease(lastPathComponent);
73 CFStringFindAndReplace(filename, CFSTR(
":"), CFSTR(
"/"), CFRangeMake(0, CFStringGetLength(filename)), 0);
75 outFileName = filename;
79 #endif // !CA_NO_CORE_SERVICES
84 char* dirname(
const char* inPath)
86 static char sAnswer[1024];
88 char* theAnswer = NULL;
89 SInt32 thePathLength = strlen(inPath);
90 if(thePathLength < 1023)
93 strcpy(sAnswer, inPath);
96 SInt32 theIndex = thePathLength - 1;
99 while((theIndex > 0) && (sAnswer[theIndex] ==
'\\'))
105 while((theIndex > 0) && (sAnswer[theIndex] !=
'\\'))
114 sAnswer[theIndex] = 0;
130 char* basename(
const char* inPath)
132 static char sAnswer[1024];
134 char* theAnswer = NULL;
135 SInt32 thePathLength = strlen(inPath);
136 if(thePathLength < 1023)
139 strcpy(sAnswer, inPath);
142 SInt32 theLastIndex = thePathLength - 1;
145 while((theLastIndex > 0) && (sAnswer[theLastIndex] ==
'\\'))
154 UInt32 theFirstIndex = theLastIndex;
155 while((theFirstIndex > 0) && (sAnswer[theFirstIndex] !=
'\\'))
161 sAnswer[theLastIndex + 1] = 0;
164 theAnswer = &sAnswer[theFirstIndex];