From 8c0bd33e0be65371a5351eb103590cb875151f9a Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sun, 25 Feb 2018 23:05:13 +0900 Subject: [PATCH] add system --- libc/system.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 libc/system.c diff --git a/libc/system.c b/libc/system.c new file mode 100644 index 00000000..c428593f --- /dev/null +++ b/libc/system.c @@ -0,0 +1,21 @@ +#include +#include +#include + +int system(const char * command) { + char * args[] = { + "/bin/sh", + "-c", + (char *)command, + NULL, + }; + pid_t pid = fork(); + if (!pid) { + execvp(args[0], args); + exit(1); + } else { + int status; + waitpid(pid, &status, 0); + return status; + } +}