From 712ea77b3edf1849acdacf88ef7ceed30a731757 Mon Sep 17 00:00:00 2001 From: Aymeric Wibo Date: Sun, 24 Nov 2024 20:31:20 +0100 Subject: [PATCH] run: Don't require the setting of `POSIXLY_CORRECT` on Linux And bring this stuff out into `cmd_add_argv`. --- src/bsys.c | 10 +--------- src/bsys/bob/main.c | 4 +--- src/cmd.c | 12 ++++++++++++ src/cmd.h | 1 + 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/bsys.c b/src/bsys.c index 0469c5a3..175149d3 100644 --- a/src/bsys.c +++ b/src/bsys.c @@ -173,15 +173,7 @@ int bsys_sh(bsys_t const* bsys, int argc, char* argv[]) { } else { - for (int i = 0; i < argc; i++) { - // On BSD/macOS, getopt doesn't consume the '--' argument. - - if (strcmp(argv[i], "--") == 0) { - continue; - } - - cmd_add(&cmd, argv[i]); - } + cmd_add_argv(&cmd, argc, argv); } if (cmd_exec_inplace(&cmd) < 0) { diff --git a/src/bsys/bob/main.c b/src/bsys/bob/main.c index 9f11f2be..6e2a7ba7 100644 --- a/src/bsys/bob/main.c +++ b/src/bsys/bob/main.c @@ -284,9 +284,7 @@ found:; // Then, add the arguments passed to the Bob frontend. // If there is no default runner, just pass the arguments from the frontend onwards. - for (ssize_t i = 0; i < argc; i++) { - cmd_add(&cmd, argv[i]); - } + cmd_add_argv(&cmd, argc, argv); // Make sure there actually is something in the command. diff --git a/src/cmd.c b/src/cmd.c index 25f32c9d..8861e251 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -71,6 +71,18 @@ __attribute__((__format__(__printf__, 2, 3))) void cmd_addf(cmd_t* cmd, char con va_end(va); } +void cmd_add_argv(cmd_t* cmd, int argc, char* argv[]) { + for (ssize_t i = 0; i < argc; i++) { + // On BSD/macOS, getopt doesn't consume the '--' argument. + + if (strcmp(argv[i], "--") == 0) { + continue; + } + + cmd_add(cmd, argv[i]); + } +} + static bool is_executable(char const* path) { struct stat sb; diff --git a/src/cmd.h b/src/cmd.h index ca21e081..ee449f2e 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -21,6 +21,7 @@ typedef struct { void cmd_create(cmd_t* cmd, ...); void cmd_add(cmd_t* cmd, char const* arg); __attribute__((__format__(__printf__, 2, 3))) void cmd_addf(cmd_t* cmd, char const* fmt, ...); +void cmd_add_argv(cmd_t* cmd, int argc, char* argv[]); int cmd_exec_inplace(cmd_t* cmd); pid_t cmd_exec_async(cmd_t* cmd); int cmd_exec(cmd_t* cmd);