Skip to content

Commit 6026766

Browse files
committed
[CF] TARGET_OS_BSD for FS representation behavior.
CFURLGetFileSystemRepresentation's implementation has TARGET_OS_MAC and TARGET_OS_LINUX, but not TARGET_OS_BSD. Nothing here appears macOS or Linux specific, and things seem to work okay with TARGET_OS_BSD, so enable it here too. This also requires CanonicalFileURLStringToFileSystemRepresentation to be exposed.
1 parent 7d0f3ea commit 6026766

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

CoreFoundation/URL.subproj/CFURL.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,7 +4064,7 @@ static CFStringRef URLPathToPOSIXPath(CFStringRef path, CFAllocatorRef allocator
40644064
return result;
40654065
}
40664066

4067-
#if TARGET_OS_MAC || TARGET_OS_LINUX
4067+
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
40684068
static Boolean CanonicalFileURLStringToFileSystemRepresentation(CFStringRef str, UInt8 *inBuffer, CFIndex inBufferLen)
40694069
{
40704070
size_t fileURLPrefixLength;
@@ -4534,13 +4534,24 @@ CFStringRef CFURLCreateStringWithFileSystemPath(CFAllocatorRef allocator, CFURLR
45344534
}
45354535

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

45414540
if (!url) return false;
4542-
#endif
4543-
#if TARGET_OS_MAC || TARGET_OS_LINUX
4541+
4542+
#if TARGET_OS_WIN32
4543+
path = CFURLCreateStringWithFileSystemPath(alloc, url, kCFURLWindowsPathStyle, resolveAgainstBase);
4544+
if (path) {
4545+
CFIndex usedLen;
4546+
CFIndex pathLen = CFStringGetLength(path);
4547+
CFIndex numConverted = CFStringGetBytes(path, CFRangeMake(0, pathLen), CFStringFileSystemEncoding(), 0, true, buffer, bufLen-1, &usedLen); // -1 because we need one byte to zero-terminate.
4548+
CFRelease(path);
4549+
if (numConverted == pathLen) {
4550+
buffer[usedLen] = '\0';
4551+
return true;
4552+
}
4553+
}
4554+
#else
45444555
if ( !resolveAgainstBase || (CFURLGetBaseURL(url) == NULL) ) {
45454556
if (!CF_IS_OBJC(CFURLGetTypeID(), url)) {
45464557
// We can access the ivars
@@ -4556,18 +4567,6 @@ Boolean CFURLGetFileSystemRepresentation(CFURLRef url, Boolean resolveAgainstBas
45564567
CFRelease(path);
45574568
return convResult;
45584569
}
4559-
#elif TARGET_OS_WIN32
4560-
path = CFURLCreateStringWithFileSystemPath(alloc, url, kCFURLWindowsPathStyle, resolveAgainstBase);
4561-
if (path) {
4562-
CFIndex usedLen;
4563-
CFIndex pathLen = CFStringGetLength(path);
4564-
CFIndex numConverted = CFStringGetBytes(path, CFRangeMake(0, pathLen), CFStringFileSystemEncoding(), 0, true, buffer, bufLen-1, &usedLen); // -1 because we need one byte to zero-terminate.
4565-
CFRelease(path);
4566-
if (numConverted == pathLen) {
4567-
buffer[usedLen] = '\0';
4568-
return true;
4569-
}
4570-
}
45714570
#endif
45724571
return false;
45734572
}

0 commit comments

Comments
 (0)