This commit is contained in:
parent
95a93a7f66
commit
eb3fb04734
@ -100,7 +100,8 @@ extern "C"
|
||||
/* Exit the program abnormally, without performing any registered cleanup actions. */
|
||||
__noreturn void _Exit(int status);
|
||||
|
||||
int system(const char*);
|
||||
/* Execute a shell command. */
|
||||
int system(const char* cmd);
|
||||
|
||||
/* Get the value of an environment variable. */
|
||||
char* getenv(const char* key);
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include <bits/waitpid.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define WIFEXITED(ret) ((ret) | 0)
|
||||
#define WEXITSTATUS(ret) ((ret)&0xff)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <luna/Utf8.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
template <typename ArgT, typename ResultT> static inline ResultT __generic_div(ArgT a, ArgT b)
|
||||
@ -175,4 +176,28 @@ extern "C"
|
||||
{
|
||||
free_impl(ptr);
|
||||
}
|
||||
|
||||
int system(const char* cmd)
|
||||
{
|
||||
if (!cmd)
|
||||
{
|
||||
// FIXME: Check if there is a shell available in the system.
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pid_t child = fork();
|
||||
if (child == 0)
|
||||
{
|
||||
execl("/bin/sh", "sh", "-c", cmd, NULL);
|
||||
_Exit(127);
|
||||
}
|
||||
|
||||
if (child < 0) return -1;
|
||||
|
||||
int status;
|
||||
waitpid(child, &status, 0);
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user