Skip to content

Commit

Permalink
run: Don't require the setting of POSIXLY_CORRECT on Linux
Browse files Browse the repository at this point in the history
And bring this stuff out into `cmd_add_argv`.
  • Loading branch information
obiwac committed Nov 24, 2024
1 parent c41cd09 commit 712ea77
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
10 changes: 1 addition & 9 deletions src/bsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/bsys/bob/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 12 additions & 0 deletions src/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 712ea77

Please sign in to comment.