Skip to content

Commit e6be742

Browse files
authored
Merge pull request #2680 from 3405691582/CFURL_FileSystemRepresentation
[CF] TARGET_OS_BSD for FS representation behavior.
2 parents ea50497 + 6026766 commit e6be742

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
@@ -4076,7 +4076,7 @@ static CFStringRef URLPathToPOSIXPath(CFStringRef path, CFAllocatorRef allocator
40764076
return result;
40774077
}
40784078

4079-
#if TARGET_OS_MAC || TARGET_OS_LINUX
4079+
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
40804080
static Boolean CanonicalFileURLStringToFileSystemRepresentation(CFStringRef str, UInt8 *inBuffer, CFIndex inBufferLen)
40814081
{
40824082
size_t fileURLPrefixLength;
@@ -4546,13 +4546,24 @@ CFStringRef CFURLCreateStringWithFileSystemPath(CFAllocatorRef allocator, CFURLR
45464546
}
45474547

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

45534552
if (!url) return false;
4554-
#endif
4555-
#if TARGET_OS_MAC || TARGET_OS_LINUX
4553+
4554+
#if TARGET_OS_WIN32
4555+
path = CFURLCreateStringWithFileSystemPath(alloc, url, kCFURLWindowsPathStyle, resolveAgainstBase);
4556+
if (path) {
4557+
CFIndex usedLen;
4558+
CFIndex pathLen = CFStringGetLength(path);
4559+
CFIndex numConverted = CFStringGetBytes(path, CFRangeMake(0, pathLen), CFStringFileSystemEncoding(), 0, true, buffer, bufLen-1, &usedLen); // -1 because we need one byte to zero-terminate.
4560+
CFRelease(path);
4561+
if (numConverted == pathLen) {
4562+
buffer[usedLen] = '\0';
4563+
return true;
4564+
}
4565+
}
4566+
#else
45564567
if ( !resolveAgainstBase || (CFURLGetBaseURL(url) == NULL) ) {
45574568
if (!CF_IS_OBJC(CFURLGetTypeID(), url)) {
45584569
// We can access the ivars
@@ -4568,18 +4579,6 @@ Boolean CFURLGetFileSystemRepresentation(CFURLRef url, Boolean resolveAgainstBas
45684579
CFRelease(path);
45694580
return convResult;
45704581
}
4571-
#elif TARGET_OS_WIN32
4572-
path = CFURLCreateStringWithFileSystemPath(alloc, url, kCFURLWindowsPathStyle, resolveAgainstBase);
4573-
if (path) {
4574-
CFIndex usedLen;
4575-
CFIndex pathLen = CFStringGetLength(path);
4576-
CFIndex numConverted = CFStringGetBytes(path, CFRangeMake(0, pathLen), CFStringFileSystemEncoding(), 0, true, buffer, bufLen-1, &usedLen); // -1 because we need one byte to zero-terminate.
4577-
CFRelease(path);
4578-
if (numConverted == pathLen) {
4579-
buffer[usedLen] = '\0';
4580-
return true;
4581-
}
4582-
}
45834582
#endif
45844583
return false;
45854584
}

0 commit comments

Comments
 (0)