@@ -105,7 +105,6 @@ CF_PRIVATE const wchar_t *_CFDLLPath(void) {
105
105
}
106
106
#endif // TARGET_OS_WIN32
107
107
108
- #if !TARGET_OS_WASI
109
108
static const char * __CFProcessPath = NULL ;
110
109
static const char * __CFprogname = NULL ;
111
110
@@ -188,6 +187,31 @@ const char *_CFProcessPath(void) {
188
187
__CFprogname = __CFProcessPath ;
189
188
}
190
189
return __CFProcessPath ;
190
+ #elif TARGET_OS_WASI
191
+ __wasi_errno_t err ;
192
+ size_t argc ;
193
+ size_t argv_buf_size ;
194
+ err = __wasi_args_sizes_get (& argc , & argv_buf_size );
195
+ if (err != 0 ) {
196
+ __CFProcessPath = "" ;
197
+ __CFprogname = __CFProcessPath ;
198
+ return __CFProcessPath ;
199
+ }
200
+ char * argv_buf = malloc (argv_buf_size );
201
+ char * * argv = calloc (argc , sizeof (char * ));
202
+ err = __wasi_args_get ((uint8_t * * )argv , (uint8_t * )argv_buf );
203
+ if (err != 0 ) {
204
+ __CFProcessPath = "" ;
205
+ __CFprogname = __CFProcessPath ;
206
+ free (argv_buf );
207
+ free (argv );
208
+ return __CFProcessPath ;
209
+ }
210
+ _CFSetProgramNameFromPath (argv [0 ]);
211
+ free (argv_buf );
212
+ free (argv );
213
+ return __CFProcessPath ;
214
+
191
215
#else // TARGET_OS_BSD
192
216
char * argv0 = NULL ;
193
217
@@ -250,7 +274,6 @@ const char *_CFProcessPath(void) {
250
274
return __CFProcessPath ;
251
275
#endif
252
276
}
253
- #endif // TARGET_OS_WASI
254
277
255
278
#if TARGET_OS_MAC || TARGET_OS_WIN32 || TARGET_OS_BSD
256
279
CF_CROSS_PLATFORM_EXPORT Boolean _CFIsMainThread (void ) {
@@ -275,7 +298,6 @@ Boolean _CFIsMainThread(void) {
275
298
}
276
299
#endif // TARGET_OS_LINUX
277
300
278
- #if !TARGET_OS_WASI
279
301
CF_PRIVATE CFStringRef _CFProcessNameString (void ) {
280
302
static CFStringRef __CFProcessNameString = NULL ;
281
303
if (!__CFProcessNameString ) {
@@ -294,7 +316,6 @@ CF_PRIVATE CFStringRef _CFProcessNameString(void) {
294
316
}
295
317
return __CFProcessNameString ;
296
318
}
297
- #endif // !TARGET_OS_WASI
298
319
299
320
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
300
321
@@ -389,16 +410,20 @@ static CFURLRef _CFCopyHomeDirURLForUser(const char *username, bool fallBackToHo
389
410
390
411
#endif
391
412
392
- #if !TARGET_OS_WASI
393
413
#define CFMaxHostNameLength 256
394
414
#define CFMaxHostNameSize (CFMaxHostNameLength+1)
395
415
396
416
CF_PRIVATE CFStringRef _CFStringCreateHostName (void ) {
417
+ #if TARGET_OS_WASI
418
+ // WASI doesn't have a concept of a hostname
419
+ return CFSTR ("" );
420
+ #else
397
421
char myName [CFMaxHostNameSize ];
398
422
399
423
// return @"" instead of nil a la CFUserName() and Ali Ozer
400
424
if (0 != gethostname (myName , CFMaxHostNameSize )) return CFSTR ("" );
401
425
return CFStringCreateWithCString (kCFAllocatorSystemDefault , myName , kCFPlatformInterfaceStringEncoding );
426
+ #endif
402
427
}
403
428
404
429
/* These are sanitized versions of the above functions. We might want to eliminate the above ones someday.
@@ -435,6 +460,8 @@ CF_EXPORT CFStringRef CFCopyUserName(void) {
435
460
result = CFStringCreateWithCString (kCFAllocatorSystemDefault , cname , kCFPlatformInterfaceStringEncoding );
436
461
}
437
462
}
463
+ #elif TARGET_OS_WASI
464
+ // WASI does not have user concept
438
465
#else
439
466
#error "Please add an implementation for CFCopyUserName() that copies the account username"
440
467
#endif
@@ -464,6 +491,8 @@ CF_CROSS_PLATFORM_EXPORT CFStringRef CFCopyFullUserName(void) {
464
491
GetUserNameExW (NameDisplay , (LPWSTR )wszBuffer , & ulLength );
465
492
466
493
result = CFStringCreateWithCharacters (kCFAllocatorSystemDefault , (UniChar * )wszBuffer , ulLength );
494
+ #elif TARGET_OS_WASI
495
+ // WASI does not have user concept
467
496
#else
468
497
#error "Please add an implementation for CFCopyFullUserName() that copies the full (display) user name"
469
498
#endif
@@ -530,6 +559,9 @@ CFURLRef CFCopyHomeDirectoryURL(void) {
530
559
if (testPath ) CFRelease (testPath );
531
560
532
561
return retVal ;
562
+ #elif TARGET_OS_WASI
563
+ // WASI does not have user concept
564
+ return NULL ;
533
565
#else
534
566
#error Dont know how to compute users home directories on this platform
535
567
#endif
@@ -661,6 +693,9 @@ CF_EXPORT CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName) {
661
693
CFAllocatorDeallocate (kCFAllocatorSystemDefault , pwszUserName );
662
694
663
695
return url ;
696
+ #elif TARGET_OS_WASI
697
+ // WASI does not have user concept
698
+ return NULL ;
664
699
#else
665
700
#error Dont know how to compute users home directories on this platform
666
701
#endif
@@ -669,7 +704,6 @@ CF_EXPORT CFURLRef CFCopyHomeDirectoryURLForUser(CFStringRef uName) {
669
704
670
705
#undef CFMaxHostNameLength
671
706
#undef CFMaxHostNameSize
672
- #endif // !TARGET_OS_WASI
673
707
674
708
#if TARGET_OS_WIN32
675
709
CF_INLINE CFIndex strlen_UniChar (const UniChar * p ) {
0 commit comments