2222#include <stdlib.h>
2323#include <stdio.h>
2424#include <string.h>
25- #if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
25+ #if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
2626#if TARGET_OS_OSX
2727#include <CoreFoundation/CFNumberFormatter.h>
2828#endif
@@ -53,9 +53,7 @@ static CFStringRef WindowsPathToURLPath(CFStringRef path, CFAllocatorRef alloc,
5353static CFStringRef POSIXPathToURLPath (CFStringRef path , CFAllocatorRef alloc , Boolean isDirectory , Boolean isAbsolute , Boolean * posixAndUrlPathsMatch ) CF_RETURNS_RETAINED ;
5454static CFStringRef CreateStringFromFileSystemRepresentationByAddingPercentEscapes (CFAllocatorRef alloc , const UInt8 * bytes , CFIndex numBytes , Boolean isDirectory , Boolean isAbsolute , Boolean windowsPath , Boolean * addedPercentEncoding ) CF_RETURNS_RETAINED ;
5555CFStringRef CFURLCreateStringWithFileSystemPath (CFAllocatorRef allocator , CFURLRef anURL , CFURLPathStyle fsType , Boolean resolveAgainstBase ) CF_RETURNS_RETAINED ;
56- #if !TARGET_OS_WASI
5756CF_EXPORT CFURLRef _CFURLCreateCurrentDirectoryURL (CFAllocatorRef allocator ) CF_RETURNS_RETAINED ;
58- #endif
5957#if TARGET_OS_MAC
6058static Boolean _CFURLHasFileURLScheme (CFURLRef url , Boolean * hasScheme );
6159#endif
@@ -2189,13 +2187,11 @@ static CFURLRef _CFURLCreateWithFileSystemPath(CFAllocatorRef allocator, CFStrin
21892187 // if fileSystemPath is an absolute path, ignore baseURL (if provided)
21902188 baseURL = NULL ;
21912189 }
2192- #if !TARGET_OS_WASI
21932190 else if ( baseURL == NULL ) {
21942191 // if fileSystemPath is a relative path and no baseURL is provided, use the current working directory
21952192 baseURL = _CFURLCreateCurrentDirectoryURL (allocator );
21962193 releaseBaseURL = true;
21972194 }
2198- #endif
21992195
22002196 // override isDirectory if the path is to root
22012197 if ( !isDirectory && (len == 1 ) && (CFStringGetCharacterAtIndex (urlString , 0 ) == '/' ) ) {
@@ -2282,7 +2278,7 @@ static CFURLRef _CFURLCreateWithFileSystemRepresentation(CFAllocatorRef allocato
22822278#endif
22832279 struct __CFURL * result = NULL ;
22842280 if (bufLen > 0 ) {
2285- #if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
2281+ #if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
22862282 Boolean isAbsolute = bufLen && (* buffer == '/' );
22872283 Boolean addedPercentEncoding ;
22882284 Boolean releaseBaseURL = false;
@@ -2292,14 +2288,12 @@ static CFURLRef _CFURLCreateWithFileSystemRepresentation(CFAllocatorRef allocato
22922288 // if buffer contains an absolute path, ignore baseURL (if provided)
22932289 baseURL = NULL ;
22942290 isFileReferencePath = _fileSystemRepresentationHasFileIDPrefix (buffer , bufLen );
2295- }
2296- #if !TARGET_OS_WASI
2297- else if ( baseURL == NULL ) {
2291+ } else if ( baseURL == NULL ) {
22982292 // if buffer contains a relative path and no baseURL is provided, use the current working directory
22992293 baseURL = _CFURLCreateCurrentDirectoryURL (allocator );
23002294 releaseBaseURL = true;
23012295 }
2302- #endif
2296+
23032297 CFStringRef urlString = CreateStringFromFileSystemRepresentationByAddingPercentEscapes (allocator , buffer , bufLen , isDirectory , isAbsolute , false /*windowsPath*/ , & addedPercentEncoding );
23042298 if ( urlString ) {
23052299 // allocate the URL object with the appropriate number of ranges
@@ -4367,7 +4361,6 @@ static CFStringRef _resolveFileSystemPaths(CFStringRef relativePath, CFStringRef
43674361 return _resolvedPath (buf , buf + baseLen + relLen , pathDelimiter , false, true, alloc );
43684362}
43694363
4370- #if !TARGET_OS_WASI
43714364CFURLRef _CFURLCreateCurrentDirectoryURL (CFAllocatorRef allocator ) {
43724365 CFURLRef url = NULL ;
43734366 // CFMaxPathSize is OK here since we're getting the path from the file system
@@ -4377,7 +4370,6 @@ CFURLRef _CFURLCreateCurrentDirectoryURL(CFAllocatorRef allocator) {
43774370 }
43784371 return url ;
43794372}
4380- #endif
43814373
43824374CFURLRef CFURLCreateWithFileSystemPath (CFAllocatorRef allocator , CFStringRef filePath , CFURLPathStyle fsType , Boolean isDirectory ) {
43834375 CFURLRef result ;
0 commit comments