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