Skip to content

[CF] TARGET_OS_BSD for FS representation behavior. #2680

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions CoreFoundation/URL.subproj/CFURL.c
Original file line number Diff line number Diff line change
Expand Up @@ -4064,7 +4064,7 @@ static CFStringRef URLPathToPOSIXPath(CFStringRef path, CFAllocatorRef allocator
return result;
}

#if TARGET_OS_MAC || TARGET_OS_LINUX
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
static Boolean CanonicalFileURLStringToFileSystemRepresentation(CFStringRef str, UInt8 *inBuffer, CFIndex inBufferLen)
{
size_t fileURLPrefixLength;
Expand Down Expand Up @@ -4534,13 +4534,24 @@ CFStringRef CFURLCreateStringWithFileSystemPath(CFAllocatorRef allocator, CFURLR
}

Boolean CFURLGetFileSystemRepresentation(CFURLRef url, Boolean resolveAgainstBase, uint8_t *buffer, CFIndex bufLen) {
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_WIN32
CFAllocatorRef alloc = CFGetAllocator(url);
CFStringRef path;

if (!url) return false;
#endif
#if TARGET_OS_MAC || TARGET_OS_LINUX

#if TARGET_OS_WIN32
path = CFURLCreateStringWithFileSystemPath(alloc, url, kCFURLWindowsPathStyle, resolveAgainstBase);
if (path) {
CFIndex usedLen;
CFIndex pathLen = CFStringGetLength(path);
CFIndex numConverted = CFStringGetBytes(path, CFRangeMake(0, pathLen), CFStringFileSystemEncoding(), 0, true, buffer, bufLen-1, &usedLen); // -1 because we need one byte to zero-terminate.
CFRelease(path);
if (numConverted == pathLen) {
buffer[usedLen] = '\0';
return true;
}
}
#else
if ( !resolveAgainstBase || (CFURLGetBaseURL(url) == NULL) ) {
if (!CF_IS_OBJC(CFURLGetTypeID(), url)) {
// We can access the ivars
Expand All @@ -4556,18 +4567,6 @@ Boolean CFURLGetFileSystemRepresentation(CFURLRef url, Boolean resolveAgainstBas
CFRelease(path);
return convResult;
}
#elif TARGET_OS_WIN32
path = CFURLCreateStringWithFileSystemPath(alloc, url, kCFURLWindowsPathStyle, resolveAgainstBase);
if (path) {
CFIndex usedLen;
CFIndex pathLen = CFStringGetLength(path);
CFIndex numConverted = CFStringGetBytes(path, CFRangeMake(0, pathLen), CFStringFileSystemEncoding(), 0, true, buffer, bufLen-1, &usedLen); // -1 because we need one byte to zero-terminate.
CFRelease(path);
if (numConverted == pathLen) {
buffer[usedLen] = '\0';
return true;
}
}
#endif
return false;
}
Expand Down