src: Use posix_spawnp instead of system() when invoking the linker

Thanks to Matteo on discord for pointing this out.
This commit is contained in:
Yawning Angel
2026-08-07 14:29:08 +09:00
parent 54b680a167
commit 9aa84b5e3a
3 changed files with 91 additions and 4 deletions

View File

@@ -739,6 +739,75 @@ gb_internal wchar_t **command_line_to_wargv(wchar_t *cmd_line, int *_argc, isize
return argv;
}
#elif defined(GB_SYSTEM_OSX) || defined(GB_SYSTEM_UNIX)
gb_internal char **command_line_to_spawn_argv(const char *cmd_line, int *_argc) {
u32 i, j;
u32 len = cast(u32)strlen(cmd_line);
i = len*gb_size_of(void *) + gb_size_of(void *);
char **argv = cast(char **)gb_alloc(gb_heap_allocator(), i + (len+1));
char *_argv = (cast(char *)argv)+i;
u32 argc = 0;
argv[argc] = _argv;
bool in_quote = false;
bool in_text = false;
bool in_space = true;
i = 0;
j = 0;
for (;;) {
char a = cmd_line[i];
if (a == 0) {
break;
}
if (in_quote) {
if (a == '\"') {
in_quote = false;
} else {
_argv[j++] = a;
}
} else {
switch (a) {
case '\"':
in_quote = true;
in_text = true;
if (in_space) {
// check_double_dash();
argv[argc++] = _argv + j;
}
in_space = false;
break;
case ' ':
case '\t':
case '\n':
case '\r':
if (in_text) _argv[j++] = '\0';
in_text = false;
in_space = true;
break;
default:
in_text = true;
if (in_space) {
// check_double_dash();
argv[argc++] = _argv + j;
}
_argv[j++] = a;
in_space = false;
break;
}
}
i++;
}
_argv[j] = '\0';
argv[argc] = nullptr;
if (_argc) *_argc = argc;
return argv;
}
#endif
#include "path.cpp"