diff --git a/src/kernel/libroot/posix/unistd/Jamfile b/src/kernel/libroot/posix/unistd/Jamfile index 29d213effb..636d126078 100644 --- a/src/kernel/libroot/posix/unistd/Jamfile +++ b/src/kernel/libroot/posix/unistd/Jamfile @@ -25,6 +25,7 @@ KernelMergeObject posix_unistd.o : sbrk.c sleep.c sync.c + system.cpp terminal.c truncate.c ttyname.c diff --git a/src/kernel/libroot/posix/unistd/system.cpp b/src/kernel/libroot/posix/unistd/system.cpp new file mode 100644 index 0000000000..0731013ec1 --- /dev/null +++ b/src/kernel/libroot/posix/unistd/system.cpp @@ -0,0 +1,37 @@ +/* +** Copyright 2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + +#include +#include + +#include + +#include + +extern "C" +int +system(const char *command) +{ + if (!command) + return 1; + + const char *argv[] = { "/bin/sh", "-c", command, NULL }; + int argc = 3; + + team_id team = _kern_create_team(argv[0], argv[0], (char**)argv, argc, NULL, + 0, B_NORMAL_PRIORITY); + if (team < 0) { + errno = team; + return -1; + } + + status_t returnValue; + status_t error = _kern_wait_for_team(team, &returnValue); + if (error != B_OK) { + errno = error; + return -1; + } + return returnValue; +}