LibC: Implement basic version of system() this assumes Shell exists

This commit is contained in:
Bananymous 2023-12-14 11:00:40 +02:00
parent 8216d09e06
commit a3de64f5fa
1 changed files with 21 additions and 0 deletions

View File

@ -71,6 +71,27 @@ char* getenv(const char* name)
return nullptr;
}
int system(const char* command)
{
// FIXME
if (command == nullptr)
return 1;
int pid = fork();
if (pid == 0)
{
execl("/bin/Shell", "Shell", "-c", command, (char*)0);
exit(1);
}
if (pid == -1)
return -1;
int stat_val;
waitpid(pid, &stat_val, 0);
return stat_val;
}
int setenv(const char* name, const char* val, int overwrite)
{
if (name == nullptr || !name[0] || strchr(name, '='))