Skip to content

Commit 50cf198

Browse files
Merge pull request #4881 from kateinoigakukun/pr-2c016a5c7b35e2c61489e5678c6777084179e273
[wasm] Unlock cwd-related APIs
2 parents 6895a0b + f634213 commit 50cf198

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ int _CFArgc(void) { return *_NSGetArgc(); }
6262
#endif
6363

6464

65-
#if !TARGET_OS_WASI
6665
CF_PRIVATE Boolean _CFGetCurrentDirectory(char *path, int maxlen) {
6766
return getcwd(path, maxlen) != NULL;
6867
}
69-
#endif
7068

7169
#if TARGET_OS_WIN32
7270
// Returns the path to the CF DLL, which we can then use to find resources like char sets

CoreFoundation/URL.subproj/CFURL.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
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,
5353
static CFStringRef POSIXPathToURLPath(CFStringRef path, CFAllocatorRef alloc, Boolean isDirectory, Boolean isAbsolute, Boolean *posixAndUrlPathsMatch) CF_RETURNS_RETAINED;
5454
static CFStringRef CreateStringFromFileSystemRepresentationByAddingPercentEscapes(CFAllocatorRef alloc, const UInt8 *bytes, CFIndex numBytes, Boolean isDirectory, Boolean isAbsolute, Boolean windowsPath, Boolean *addedPercentEncoding) CF_RETURNS_RETAINED;
5555
CFStringRef CFURLCreateStringWithFileSystemPath(CFAllocatorRef allocator, CFURLRef anURL, CFURLPathStyle fsType, Boolean resolveAgainstBase) CF_RETURNS_RETAINED;
56-
#if !TARGET_OS_WASI
5756
CF_EXPORT CFURLRef _CFURLCreateCurrentDirectoryURL(CFAllocatorRef allocator) CF_RETURNS_RETAINED;
58-
#endif
5957
#if TARGET_OS_MAC
6058
static 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
43714364
CFURLRef _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

43824374
CFURLRef CFURLCreateWithFileSystemPath(CFAllocatorRef allocator, CFStringRef filePath, CFURLPathStyle fsType, Boolean isDirectory) {
43834375
CFURLRef result;

0 commit comments

Comments
 (0)