22
22
#include <stdlib.h>
23
23
#include <stdio.h>
24
24
#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
26
26
#if TARGET_OS_OSX
27
27
#include <CoreFoundation/CFNumberFormatter.h>
28
28
#endif
@@ -53,9 +53,7 @@ static CFStringRef WindowsPathToURLPath(CFStringRef path, CFAllocatorRef alloc,
53
53
static CFStringRef POSIXPathToURLPath (CFStringRef path , CFAllocatorRef alloc , Boolean isDirectory , Boolean isAbsolute , Boolean * posixAndUrlPathsMatch ) CF_RETURNS_RETAINED ;
54
54
static CFStringRef CreateStringFromFileSystemRepresentationByAddingPercentEscapes (CFAllocatorRef alloc , const UInt8 * bytes , CFIndex numBytes , Boolean isDirectory , Boolean isAbsolute , Boolean windowsPath , Boolean * addedPercentEncoding ) CF_RETURNS_RETAINED ;
55
55
CFStringRef CFURLCreateStringWithFileSystemPath (CFAllocatorRef allocator , CFURLRef anURL , CFURLPathStyle fsType , Boolean resolveAgainstBase ) CF_RETURNS_RETAINED ;
56
- #if !TARGET_OS_WASI
57
56
CF_EXPORT CFURLRef _CFURLCreateCurrentDirectoryURL (CFAllocatorRef allocator ) CF_RETURNS_RETAINED ;
58
- #endif
59
57
#if TARGET_OS_MAC
60
58
static Boolean _CFURLHasFileURLScheme (CFURLRef url , Boolean * hasScheme );
61
59
#endif
@@ -2189,13 +2187,11 @@ static CFURLRef _CFURLCreateWithFileSystemPath(CFAllocatorRef allocator, CFStrin
2189
2187
// if fileSystemPath is an absolute path, ignore baseURL (if provided)
2190
2188
baseURL = NULL ;
2191
2189
}
2192
- #if !TARGET_OS_WASI
2193
2190
else if ( baseURL == NULL ) {
2194
2191
// if fileSystemPath is a relative path and no baseURL is provided, use the current working directory
2195
2192
baseURL = _CFURLCreateCurrentDirectoryURL (allocator );
2196
2193
releaseBaseURL = true;
2197
2194
}
2198
- #endif
2199
2195
2200
2196
// override isDirectory if the path is to root
2201
2197
if ( !isDirectory && (len == 1 ) && (CFStringGetCharacterAtIndex (urlString , 0 ) == '/' ) ) {
@@ -2282,7 +2278,7 @@ static CFURLRef _CFURLCreateWithFileSystemRepresentation(CFAllocatorRef allocato
2282
2278
#endif
2283
2279
struct __CFURL * result = NULL ;
2284
2280
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
2286
2282
Boolean isAbsolute = bufLen && (* buffer == '/' );
2287
2283
Boolean addedPercentEncoding ;
2288
2284
Boolean releaseBaseURL = false;
@@ -2292,14 +2288,12 @@ static CFURLRef _CFURLCreateWithFileSystemRepresentation(CFAllocatorRef allocato
2292
2288
// if buffer contains an absolute path, ignore baseURL (if provided)
2293
2289
baseURL = NULL ;
2294
2290
isFileReferencePath = _fileSystemRepresentationHasFileIDPrefix (buffer , bufLen );
2295
- }
2296
- #if !TARGET_OS_WASI
2297
- else if ( baseURL == NULL ) {
2291
+ } else if ( baseURL == NULL ) {
2298
2292
// if buffer contains a relative path and no baseURL is provided, use the current working directory
2299
2293
baseURL = _CFURLCreateCurrentDirectoryURL (allocator );
2300
2294
releaseBaseURL = true;
2301
2295
}
2302
- #endif
2296
+
2303
2297
CFStringRef urlString = CreateStringFromFileSystemRepresentationByAddingPercentEscapes (allocator , buffer , bufLen , isDirectory , isAbsolute , false /*windowsPath*/ , & addedPercentEncoding );
2304
2298
if ( urlString ) {
2305
2299
// allocate the URL object with the appropriate number of ranges
@@ -4367,7 +4361,6 @@ static CFStringRef _resolveFileSystemPaths(CFStringRef relativePath, CFStringRef
4367
4361
return _resolvedPath (buf , buf + baseLen + relLen , pathDelimiter , false, true, alloc );
4368
4362
}
4369
4363
4370
- #if !TARGET_OS_WASI
4371
4364
CFURLRef _CFURLCreateCurrentDirectoryURL (CFAllocatorRef allocator ) {
4372
4365
CFURLRef url = NULL ;
4373
4366
// CFMaxPathSize is OK here since we're getting the path from the file system
@@ -4377,7 +4370,6 @@ CFURLRef _CFURLCreateCurrentDirectoryURL(CFAllocatorRef allocator) {
4377
4370
}
4378
4371
return url ;
4379
4372
}
4380
- #endif
4381
4373
4382
4374
CFURLRef CFURLCreateWithFileSystemPath (CFAllocatorRef allocator , CFStringRef filePath , CFURLPathStyle fsType , Boolean isDirectory ) {
4383
4375
CFURLRef result ;
0 commit comments