stdlib.h: implement mkstemp()
[neatlibc.git] / unistd.c
blobf021722ed914bf561283481b36b1f74cfb33d86f
1 #include <time.h>
2 #include <stdarg.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <signal.h>
8 int sleep(int n)
10 struct timespec req = {n, 0};
11 struct timespec rem;
12 if (nanosleep(&req, &rem))
13 return rem.tv_sec;
14 return 0;
17 #define EXECARGS (1 << 7)
19 int execle(char *path, ...)
21 va_list ap;
22 char *argv[EXECARGS];
23 char **envp;
24 int argc = 0;
25 va_start(ap, path);
26 while (argc + 1 < EXECARGS && (argv[argc] = va_arg(ap, char *)))
27 argc++;
28 envp = va_arg(ap, char **);
29 va_end(ap);
30 argv[argc] = NULL;
31 execve(path, argv, envp);
32 return -1;
35 int execvp(char *cmd, char *argv[])
37 char path[512];
38 char *p = getenv("PATH");
39 if (strchr(cmd, '/'))
40 return execve(cmd, argv, environ);
41 if (!p)
42 p = "/bin";
43 while (*p) {
44 char *s = path;
45 while (*p && *p != ':')
46 *s++ = *p++;
47 if (s != path)
48 *s++ = '/';
49 strcpy(s, cmd);
50 execve(path, argv, environ);
51 if (*p == ':')
52 p++;
54 return -1;
57 int wait(int *status)
59 return waitpid(-1, status, 0);
62 int raise(int sig)
64 return kill(getpid(), sig);
67 void abort(void)
69 raise(SIGABRT);
70 while (1)