scc

A fork of https://git.simple-cc.org/scc/ for Qute

git clone https://git.8pit.net/scc.git

 1#include <sys.h>
 2
 3#include <errno.h>
 4#include <stdlib.h>
 5
 6#include "../../syscall.h"
 7
 8#define SHELL "/bin/sh"
 9
10#undef system
11
12int
13system(const char *cmd)
14{
15	int st;
16	pid_t pid;
17
18	if (!cmd)
19		return _access(SHELL, X_OK);
20
21	switch ((pid = _fork())) {
22	case -1:
23		return -1;
24	case 0:
25		_execve(SHELL, (const char*[]) {"sh", "-c", cmd, NULL}, _environ);
26		_exit(127);
27	default:
28		while (_waitpid(pid, &st, 0) < 0 && errno == EINTR)
29			;
30		return st;
31	}
32}