@@ -94,23 +94,27 @@ int pthread_fchdir_np(int fd)
9494
9595#if !defined(_WIN32) && defined(HAVE_POSIX_SPAWN)
9696// Implementation mostly copied from _CFPosixSpawnFileActionsChdir in swift-corelibs-foundation
97- static int posix_spawn_file_actions_addchdir (posix_spawn_file_actions_t * __restrict file_actions,
98- const char * __restrict path) {
97+ static int posix_spawn_file_actions_addchdir_polyfill (posix_spawn_file_actions_t * __restrict file_actions,
98+ const char * __restrict path) {
9999#if defined(__GLIBC__) && !__GLIBC_PREREQ(2, 29)
100100 // Glibc versions prior to 2.29 don't support posix_spawn_file_actions_addchdir_np, impacting:
101101 // - Amazon Linux 2 (EoL mid-2025)
102102 return ENOSYS;
103+ #elif defined(__ANDROID__) && __ANDROID_API__ < 34
104+ // Android versions prior to 14 (API level 34) don't support posix_spawn_file_actions_addchdir_np
105+ return ENOSYS;
106+ #elif defined(__OpenBSD__) || defined(__QNX__)
107+ // Currently missing as of:
108+ // - OpenBSD 7.5 (April 2024)
109+ // - QNX 8 (December 2023)
110+ return ENOSYS;
103111#elif defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
104112 // Conditionally available on macOS if building with a deployment target older than 10.15
105113 if (__builtin_available (macOS 10.15 , *)) {
106114 return posix_spawn_file_actions_addchdir_np (file_actions, path);
107115 }
108116 return ENOSYS;
109- #elif defined(__OpenBSD__)
110- // Currently missing as of:
111- // - OpenBSD 7.5 (April 2024)
112- return ENOSYS;
113- #elif defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || (defined(__ANDROID__) && __ANDROID_API__ >= 34) || defined(__musl__)
117+ #elif defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__ANDROID__) || defined(__musl__)
114118 // Pre-standard posix_spawn_file_actions_addchdir_np version available in:
115119 // - Solaris 11.3 (October 2015)
116120 // - Glibc 2.29 (February 2019)
@@ -123,7 +127,6 @@ static int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t * __rest
123127 // Standardized posix_spawn_file_actions_addchdir version (POSIX.1-2024, June 2024) available in:
124128 // - Solaris 11.4 (August 2018)
125129 // - NetBSD 10.0 (March 2024)
126- // - QNX 8 (December 2023)
127130 return posix_spawn_file_actions_addchdir ((posix_spawn_file_actions_t *)file_actions, path);
128131#endif
129132}
@@ -1106,7 +1109,7 @@ void spawnProcess(
11061109 bool usePosixSpawnChdirFallback = true ;
11071110 const auto workingDir = attr.workingDir ;
11081111 if (!workingDir.empty () &&
1109- posix_spawn_file_actions_addchdir (&fileActions, workingDir.c_str ()) != ENOSYS) {
1112+ posix_spawn_file_actions_addchdir_polyfill (&fileActions, workingDir.c_str ()) != ENOSYS) {
11101113 usePosixSpawnChdirFallback = false ;
11111114 }
11121115
0 commit comments