Skip to content

Commit 84cd6be

Browse files
Prefer TARGET_OS_WASI over __wasi__
And explain why we need definition checks for `signal.h` and `sys/mman.h`
1 parent f125402 commit 84cd6be

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/_FoundationCShims/include/_CStdlib.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,19 @@
6060
#endif
6161

6262
#if __has_include(<signal.h>)
63-
/* wasi-libc's signal.h is available only if _WASI_EMULATED_SIGNAL is defined */
64-
# if !defined(__wasi__) || defined(_WASI_EMULATED_SIGNAL)
63+
/// Guard against including `signal.h` on WASI. The `signal.h` header file
64+
/// itself is available in wasi-libc, but it's just a stub that doesn't actually
65+
/// do anything. And also including it requires a special macro definition
66+
/// (`_WASI_EMULATED_SIGNAL`) and it causes compilation errors without the macro.
67+
# if !TARGET_OS_WASI || defined(_WASI_EMULATED_SIGNAL)
6568
# include <signal.h>
6669
# endif
6770
#endif
6871

6972
#if __has_include(<sys/mman.h>)
70-
/* wasi-libc's mman.h is available only if _WASI_EMULATED_MMAN is defined */
71-
# if !defined(__wasi__) || defined(_WASI_EMULATED_MMAN)
73+
/// Similar to `signal.h`, guard against including `sys/mman.h` on WASI unless
74+
/// `_WASI_EMULATED_MMAN` is enabled.
75+
# if !TARGET_OS_WASI || defined(_WASI_EMULATED_MMAN)
7276
# include <sys/mman.h>
7377
# endif
7478
#endif

0 commit comments

Comments
 (0)