Skip to content

Instantly share code, notes, and snippets.

@vanhoefm
Created November 5, 2012 19:16

Revisions

  1. vanhoefm created this gist Nov 5, 2012.
    17 changes: 17 additions & 0 deletions sysdeps\posix\system.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #define SHELL_PATH "/bin/sh" /* Path of the shell. */
    #define SHELL_NAME "sh" /* Name to give it. */

    static int do_system(const char *line)
    {
    if (fork() == 0) {
    const char *new_argv[4];
    new_argv[0] = SHELL_NAME;
    new_argv[1] = "-c";
    new_argv[2] = line;
    new_argv[3] = NULL;

    execve(SELL_PATH, (char *const *) new_argv, __environ);
    } else {
    // wait on child
    }
    }