vendor : apply patches for subprocess.h (#26606)
This commit is contained in:
Vendored
+59
-30
@@ -274,6 +274,21 @@ subprocess_weak int subprocess_alive(struct subprocess_s *const process);
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* Whether subprocess_create_ex can honour process_cwd. glibc only gained
|
||||
posix_spawn_file_actions_addchdir_np in 2.29. Define this yourself to
|
||||
override the detection, for instance on musl older than 1.1.24. */
|
||||
#if !defined(SUBPROCESS_HAVE_CWD)
|
||||
#if defined(__GLIBC__)
|
||||
#if __GLIBC_PREREQ(2, 29)
|
||||
#define SUBPROCESS_HAVE_CWD 1
|
||||
#else
|
||||
#define SUBPROCESS_HAVE_CWD 0
|
||||
#endif
|
||||
#else
|
||||
#define SUBPROCESS_HAVE_CWD 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
#include <wchar.h>
|
||||
@@ -653,6 +668,7 @@ int subprocess_create_ex(const char *const commandLine[], int options,
|
||||
int wide_len;
|
||||
int i, j;
|
||||
int need_quoting;
|
||||
subprocess_size_t bs_run;
|
||||
unsigned long flags = 0;
|
||||
unsigned long last_error = 0;
|
||||
int result = subprocess_error_unknown;
|
||||
@@ -906,25 +922,29 @@ int subprocess_create_ex(const char *const commandLine[], int options,
|
||||
len++;
|
||||
|
||||
// Quote the argument if it has a space in it
|
||||
if (strpbrk(commandLine[i], "\t\v ") != SUBPROCESS_NULL ||
|
||||
commandLine[i][0] == SUBPROCESS_NULL)
|
||||
need_quoting = strpbrk(commandLine[i], "\t\v ") != SUBPROCESS_NULL ||
|
||||
commandLine[i][0] == SUBPROCESS_NULL;
|
||||
if (need_quoting)
|
||||
len += 2;
|
||||
|
||||
bs_run = 0;
|
||||
for (j = 0; '\0' != commandLine[i][j]; j++) {
|
||||
switch (commandLine[i][j]) {
|
||||
default:
|
||||
break;
|
||||
case '\\':
|
||||
if (commandLine[i][j + 1] == '"') {
|
||||
len++;
|
||||
}
|
||||
|
||||
break;
|
||||
case '"':
|
||||
len++;
|
||||
break;
|
||||
}
|
||||
len++;
|
||||
|
||||
if ('\\' == commandLine[i][j]) {
|
||||
bs_run++;
|
||||
} else {
|
||||
if ('"' == commandLine[i][j]) {
|
||||
// Duplicate the preceding run and escape the quote.
|
||||
len += bs_run + 1;
|
||||
}
|
||||
bs_run = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (need_quoting) {
|
||||
// Duplicate trailing slashes before the generated closing quote.
|
||||
len += bs_run;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,22 +969,29 @@ int subprocess_create_ex(const char *const commandLine[], int options,
|
||||
commandLineCombined[len++] = '"';
|
||||
}
|
||||
|
||||
for (j = 0; '\0' != commandLine[i][j]; j++) {
|
||||
switch (commandLine[i][j]) {
|
||||
default:
|
||||
break;
|
||||
case '\\':
|
||||
if (commandLine[i][j + 1] == '"') {
|
||||
commandLineCombined[len++] = '\\';
|
||||
}
|
||||
|
||||
break;
|
||||
case '"':
|
||||
commandLineCombined[len++] = '\\';
|
||||
break;
|
||||
for (j = 0; '\0' != commandLine[i][j];) {
|
||||
bs_run = 0;
|
||||
while ('\\' == commandLine[i][j]) {
|
||||
bs_run++;
|
||||
j++;
|
||||
}
|
||||
|
||||
commandLineCombined[len++] = commandLine[i][j];
|
||||
if ('"' == commandLine[i][j]) {
|
||||
// 2n + 1 slashes preserve n slashes and escape the quote.
|
||||
bs_run = (bs_run * 2) + 1;
|
||||
} else if ('\0' == commandLine[i][j] && need_quoting) {
|
||||
// 2n slashes preserve n slashes before the closing quote.
|
||||
bs_run *= 2;
|
||||
}
|
||||
|
||||
while (bs_run > 0) {
|
||||
commandLineCombined[len++] = '\\';
|
||||
bs_run--;
|
||||
}
|
||||
|
||||
if ('\0' != commandLine[i][j]) {
|
||||
commandLineCombined[len++] = commandLine[i][j++];
|
||||
}
|
||||
}
|
||||
if (need_quoting) {
|
||||
commandLineCombined[len++] = '"';
|
||||
@@ -1205,8 +1232,10 @@ cleanup:
|
||||
|
||||
// Set working directory
|
||||
if (process_cwd) {
|
||||
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000
|
||||
#if defined(__NetBSD__) || (defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 260000)
|
||||
posix_error = posix_spawn_file_actions_addchdir(&actions, process_cwd);
|
||||
#elif !SUBPROCESS_HAVE_CWD
|
||||
posix_error = ENOSYS;
|
||||
#else
|
||||
#if defined(__APPLE__) && defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
|
||||
Reference in New Issue
Block a user