summaryrefslogtreecommitdiff
path: root/src/unistd
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-09 13:14:01 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-09 13:14:01 -0500
commit253a32e2f9ff1cbb8edbe7c79834a678daebeb93 (patch)
tree599cf5baf01c6dae33a2f89989b08b7d553f7fd0 /src/unistd
parent88d0b5e7ffbf0554b236dc46225846061b5f4817 (diff)
merge POSIX.1-1988/1990
Diffstat (limited to 'src/unistd')
-rw-r--r--src/unistd/F_OK.c5
-rw-r--r--src/unistd/R_OK.c5
-rw-r--r--src/unistd/STDERR_FILENO.c5
-rw-r--r--src/unistd/STDIN_FILENO.c5
-rw-r--r--src/unistd/STDOUT_FILENO.c5
-rw-r--r--src/unistd/W_OK.c5
-rw-r--r--src/unistd/X_OK.c5
-rw-r--r--src/unistd/_PC_CHOWN_RESTRICTED.c5
-rw-r--r--src/unistd/_PC_LINK_MAX.c5
-rw-r--r--src/unistd/_PC_MAX_CANON.c5
-rw-r--r--src/unistd/_PC_MAX_INPUT.c5
-rw-r--r--src/unistd/_PC_NAME_MAX.c5
-rw-r--r--src/unistd/_PC_NO_TRUNC.c5
-rw-r--r--src/unistd/_PC_PATH_MAX.c5
-rw-r--r--src/unistd/_PC_PIPE_BUF.c5
-rw-r--r--src/unistd/_PC_VDISABLE.c5
-rw-r--r--src/unistd/_POSIX_CHOWN_RESTRICTED.c6
-rw-r--r--src/unistd/_POSIX_JOB_CONTROL.c5
-rw-r--r--src/unistd/_POSIX_NO_TRUNC.c6
-rw-r--r--src/unistd/_POSIX_SAVED_IDS.c5
-rw-r--r--src/unistd/_POSIX_VDISABLE.c6
-rw-r--r--src/unistd/_POSIX_VERSION.c17
-rw-r--r--src/unistd/_SC_ARG_MAX.c5
-rw-r--r--src/unistd/_SC_CHILD_MAX.c5
-rw-r--r--src/unistd/_SC_CLK_TCK.c5
-rw-r--r--src/unistd/_SC_JOB_CONTROL.c5
-rw-r--r--src/unistd/_SC_NGROUPS_MAX.c5
-rw-r--r--src/unistd/_SC_OPEN_MAX.c5
-rw-r--r--src/unistd/_SC_SAVED_IDS.c5
-rw-r--r--src/unistd/_SC_STREAM_MAX.c7
-rw-r--r--src/unistd/_SC_TZNAME_MAX.c7
-rw-r--r--src/unistd/_SC_VERSION.c5
-rw-r--r--src/unistd/_exit.c13
-rw-r--r--src/unistd/access.c43
-rw-r--r--src/unistd/alarm.c16
-rw-r--r--src/unistd/chdir.c12
-rw-r--r--src/unistd/chown.c12
-rw-r--r--src/unistd/close.c12
-rw-r--r--src/unistd/ctermid.c21
-rw-r--r--src/unistd/dup.c12
-rw-r--r--src/unistd/dup2.c29
-rw-r--r--src/unistd/execl.c24
-rw-r--r--src/unistd/execle.c26
-rw-r--r--src/unistd/execlp.c24
-rw-r--r--src/unistd/execv.c12
-rw-r--r--src/unistd/execve.c14
-rw-r--r--src/unistd/execvp.c20
-rw-r--r--src/unistd/fork.c13
-rw-r--r--src/unistd/fpathconf.c12
-rw-r--r--src/unistd/getcwd.c21
-rw-r--r--src/unistd/getegid.c12
-rw-r--r--src/unistd/geteuid.c12
-rw-r--r--src/unistd/getgid.c12
-rw-r--r--src/unistd/getgroups.c17
-rw-r--r--src/unistd/getlogin.c11
-rw-r--r--src/unistd/getpgrp.c12
-rw-r--r--src/unistd/getpid.c12
-rw-r--r--src/unistd/getppid.c12
-rw-r--r--src/unistd/getuid.c12
-rw-r--r--src/unistd/isatty.c19
-rw-r--r--src/unistd/link.c12
-rw-r--r--src/unistd/lseek.c12
-rw-r--r--src/unistd/pathconf.c12
-rw-r--r--src/unistd/pause.c13
-rw-r--r--src/unistd/pipe.c14
-rw-r--r--src/unistd/read.c13
-rw-r--r--src/unistd/rmdir.c13
-rw-r--r--src/unistd/setgid.c13
-rw-r--r--src/unistd/setpgid.c13
-rw-r--r--src/unistd/setsid.c12
-rw-r--r--src/unistd/setuid.c12
-rw-r--r--src/unistd/sleep.c16
-rw-r--r--src/unistd/sysconf.c11
-rw-r--r--src/unistd/tcgetpgrp.c13
-rw-r--r--src/unistd/tcsetpgrp.c13
-rw-r--r--src/unistd/ttyname.c12
-rw-r--r--src/unistd/unlink.c14
-rw-r--r--src/unistd/write.c16
78 files changed, 880 insertions, 0 deletions
diff --git a/src/unistd/F_OK.c b/src/unistd/F_OK.c
new file mode 100644
index 00000000..1c97b651
--- /dev/null
+++ b/src/unistd/F_OK.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define F_OK 8
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/R_OK.c b/src/unistd/R_OK.c
new file mode 100644
index 00000000..367b3d8a
--- /dev/null
+++ b/src/unistd/R_OK.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define R_OK 4
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/STDERR_FILENO.c b/src/unistd/STDERR_FILENO.c
new file mode 100644
index 00000000..f2c75dde
--- /dev/null
+++ b/src/unistd/STDERR_FILENO.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define STDERR_FILENO 2
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/STDIN_FILENO.c b/src/unistd/STDIN_FILENO.c
new file mode 100644
index 00000000..550b080e
--- /dev/null
+++ b/src/unistd/STDIN_FILENO.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define STDIN_FILENO 0
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/STDOUT_FILENO.c b/src/unistd/STDOUT_FILENO.c
new file mode 100644
index 00000000..d1aca0c9
--- /dev/null
+++ b/src/unistd/STDOUT_FILENO.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define STDOUT_FILENO 1
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/W_OK.c b/src/unistd/W_OK.c
new file mode 100644
index 00000000..387adb7a
--- /dev/null
+++ b/src/unistd/W_OK.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define W_OK 2
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/X_OK.c b/src/unistd/X_OK.c
new file mode 100644
index 00000000..f097b19e
--- /dev/null
+++ b/src/unistd/X_OK.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define X_OK 1
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_CHOWN_RESTRICTED.c b/src/unistd/_PC_CHOWN_RESTRICTED.c
new file mode 100644
index 00000000..6f5589db
--- /dev/null
+++ b/src/unistd/_PC_CHOWN_RESTRICTED.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_CHOWN_RESTRICTED 3
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_LINK_MAX.c b/src/unistd/_PC_LINK_MAX.c
new file mode 100644
index 00000000..bab6528f
--- /dev/null
+++ b/src/unistd/_PC_LINK_MAX.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_LINK_MAX 5
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_MAX_CANON.c b/src/unistd/_PC_MAX_CANON.c
new file mode 100644
index 00000000..1e23c04c
--- /dev/null
+++ b/src/unistd/_PC_MAX_CANON.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_MAX_CANON 6
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_MAX_INPUT.c b/src/unistd/_PC_MAX_INPUT.c
new file mode 100644
index 00000000..bc7bb3bc
--- /dev/null
+++ b/src/unistd/_PC_MAX_INPUT.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_MAX_INPUT 7
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_NAME_MAX.c b/src/unistd/_PC_NAME_MAX.c
new file mode 100644
index 00000000..bb9698e3
--- /dev/null
+++ b/src/unistd/_PC_NAME_MAX.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_NAME_MAX 8
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_NO_TRUNC.c b/src/unistd/_PC_NO_TRUNC.c
new file mode 100644
index 00000000..9a83e5cb
--- /dev/null
+++ b/src/unistd/_PC_NO_TRUNC.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_NO_TRUNC 9
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_PATH_MAX.c b/src/unistd/_PC_PATH_MAX.c
new file mode 100644
index 00000000..1c5dcf8a
--- /dev/null
+++ b/src/unistd/_PC_PATH_MAX.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_PATH_MAX 10
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_PIPE_BUF.c b/src/unistd/_PC_PIPE_BUF.c
new file mode 100644
index 00000000..038827a2
--- /dev/null
+++ b/src/unistd/_PC_PIPE_BUF.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_PIPE_BUF 11
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_PC_VDISABLE.c b/src/unistd/_PC_VDISABLE.c
new file mode 100644
index 00000000..5056367b
--- /dev/null
+++ b/src/unistd/_PC_VDISABLE.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _PC_VDISABLE 20
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_POSIX_CHOWN_RESTRICTED.c b/src/unistd/_POSIX_CHOWN_RESTRICTED.c
new file mode 100644
index 00000000..c3404e5e
--- /dev/null
+++ b/src/unistd/_POSIX_CHOWN_RESTRICTED.c
@@ -0,0 +1,6 @@
+#include <unistd.h>
+#define _POSIX_CHOWN_RESTRICTED (1)
+/* USE: pathconf() */
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_POSIX_JOB_CONTROL.c b/src/unistd/_POSIX_JOB_CONTROL.c
new file mode 100644
index 00000000..37a1c9c8
--- /dev/null
+++ b/src/unistd/_POSIX_JOB_CONTROL.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _POSIX_JOB_CONTROL (_POSIX_C_SOURCE)
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_POSIX_NO_TRUNC.c b/src/unistd/_POSIX_NO_TRUNC.c
new file mode 100644
index 00000000..5ed641a8
--- /dev/null
+++ b/src/unistd/_POSIX_NO_TRUNC.c
@@ -0,0 +1,6 @@
+#include <unistd.h>
+#define _POSIX_NO_TRUNC (2)
+/* USE: pathconf */
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_POSIX_SAVED_IDS.c b/src/unistd/_POSIX_SAVED_IDS.c
new file mode 100644
index 00000000..16058a22
--- /dev/null
+++ b/src/unistd/_POSIX_SAVED_IDS.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _POSIX_SAVED_IDS (_POSIX_C_SOURCE)
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_POSIX_VDISABLE.c b/src/unistd/_POSIX_VDISABLE.c
new file mode 100644
index 00000000..41aef6fe
--- /dev/null
+++ b/src/unistd/_POSIX_VDISABLE.c
@@ -0,0 +1,6 @@
+#include <unistd.h>
+#define _POSIX_VDISABLE (3)
+/* USE: pathconf() */
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_POSIX_VERSION.c b/src/unistd/_POSIX_VERSION.c
new file mode 100644
index 00000000..d9552154
--- /dev/null
+++ b/src/unistd/_POSIX_VERSION.c
@@ -0,0 +1,17 @@
+#include <unistd.h>
+#if _POSIX_C_SOURCE >= 200809L
+#define _POSIX_VERISON (200809L)
+#elif _POSIX_C_SOURCE >= 200112L
+#define _POSIX_VERSION (200112L)
+#elif _POSIX_C_SOURCE >= 199506L
+#define _POSIX_VERSION (199506L)
+#elif _POSIX_C_SOURCE >= 199309L
+#define _POSIX_VERSION (199309L)
+#elif defined _POSIX_C_SOURCE
+#define _POSIX_VERSION (199009L)
+#else
+#define _POSIX_VERSION (198808L)
+#endif
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_ARG_MAX.c b/src/unistd/_SC_ARG_MAX.c
new file mode 100644
index 00000000..11d04582
--- /dev/null
+++ b/src/unistd/_SC_ARG_MAX.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_ARG_MAX 19
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_CHILD_MAX.c b/src/unistd/_SC_CHILD_MAX.c
new file mode 100644
index 00000000..c4c7fdfa
--- /dev/null
+++ b/src/unistd/_SC_CHILD_MAX.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_CHILD_MAX 27
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_CLK_TCK.c b/src/unistd/_SC_CLK_TCK.c
new file mode 100644
index 00000000..11924761
--- /dev/null
+++ b/src/unistd/_SC_CLK_TCK.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_CLK_TCK 28
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_JOB_CONTROL.c b/src/unistd/_SC_JOB_CONTROL.c
new file mode 100644
index 00000000..95fe71e4
--- /dev/null
+++ b/src/unistd/_SC_JOB_CONTROL.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_JOB_CONTROL 40
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_NGROUPS_MAX.c b/src/unistd/_SC_NGROUPS_MAX.c
new file mode 100644
index 00000000..b8245ff1
--- /dev/null
+++ b/src/unistd/_SC_NGROUPS_MAX.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_NGROUPS_MAX 51
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_OPEN_MAX.c b/src/unistd/_SC_OPEN_MAX.c
new file mode 100644
index 00000000..901c8257
--- /dev/null
+++ b/src/unistd/_SC_OPEN_MAX.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_OPEN_MAX 52
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_SAVED_IDS.c b/src/unistd/_SC_SAVED_IDS.c
new file mode 100644
index 00000000..fec11730
--- /dev/null
+++ b/src/unistd/_SC_SAVED_IDS.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_SAVED_IDS 63
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_STREAM_MAX.c b/src/unistd/_SC_STREAM_MAX.c
new file mode 100644
index 00000000..206af307
--- /dev/null
+++ b/src/unistd/_SC_STREAM_MAX.c
@@ -0,0 +1,7 @@
+#include <unistd.h>
+
+#define _SC_STREAM_MAX 74
+
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_TZNAME_MAX.c b/src/unistd/_SC_TZNAME_MAX.c
new file mode 100644
index 00000000..86eea892
--- /dev/null
+++ b/src/unistd/_SC_TZNAME_MAX.c
@@ -0,0 +1,7 @@
+#include <unistd.h>
+
+#define _SC_TZNAME_MAX 106
+
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_SC_VERSION.c b/src/unistd/_SC_VERSION.c
new file mode 100644
index 00000000..e3310b91
--- /dev/null
+++ b/src/unistd/_SC_VERSION.c
@@ -0,0 +1,5 @@
+#include <unistd.h>
+#define _SC_VERSION 115
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/_exit.c b/src/unistd/_exit.c
new file mode 100644
index 00000000..fde6d675
--- /dev/null
+++ b/src/unistd/_exit.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+void _exit(int status)
+{
+ __libc.syscall(__libc.syscall_lookup("exit"), status);
+ for (;;);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/access.c b/src/unistd/access.c
new file mode 100644
index 00000000..25554edf
--- /dev/null
+++ b/src/unistd/access.c
@@ -0,0 +1,43 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "sys/stat.h"
+
+int access(const char *path, int amode)
+{
+ struct stat st;
+ mode_t check = (amode & R_OK ? 4 : 0)
+ | (amode & W_OK ? 2 : 0)
+ | (amode & X_OK ? 1 : 0);
+
+ if (amode != F_OK && ((amode & ~(R_OK | W_OK | X_OK)) != 0)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (stat(path, &st) == -1) {
+ /* errno set by stat() */
+ return -1;
+ }
+
+ if (amode == F_OK) {
+ return 0;
+ }
+
+ if (st.st_uid == getuid()) {
+ check <<= 6;
+ } else if (st.st_gid == getgid()) {
+ check <<= 3;
+ }
+
+ if ((st.st_mode & check) == check) {
+ return 0;
+ }
+
+ errno = EACCES;
+ return -1;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/alarm.c b/src/unistd/alarm.c
new file mode 100644
index 00000000..ff96dbaa
--- /dev/null
+++ b/src/unistd/alarm.c
@@ -0,0 +1,16 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+unsigned alarm(unsigned seconds)
+{
+ #if 0
+ SC(unsigned, seconds);
+ #else
+ return seconds;
+ #endif
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/chdir.c b/src/unistd/chdir.c
new file mode 100644
index 00000000..82dc997a
--- /dev/null
+++ b/src/unistd/chdir.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+int chdir(const char *path)
+{
+ SC(int, path);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/chown.c b/src/unistd/chown.c
new file mode 100644
index 00000000..55b32b07
--- /dev/null
+++ b/src/unistd/chown.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+int chown(const char *path, uid_t owner, gid_t group)
+{
+ SC(int, path, owner, group);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/close.c b/src/unistd/close.c
new file mode 100644
index 00000000..b4f402eb
--- /dev/null
+++ b/src/unistd/close.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+int close(int fildes)
+{
+ SC(int, fildes);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/ctermid.c b/src/unistd/ctermid.c
new file mode 100644
index 00000000..32a47b64
--- /dev/null
+++ b/src/unistd/ctermid.c
@@ -0,0 +1,21 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "stdio.h"
+#include "string.h"
+
+char * ctermid(char * s)
+{
+ static char termid[L_ctermid] = "/dev/tty";
+
+ if (s == NULL) {
+ s = termid;
+ } else {
+ strcpy(s, termid);
+ }
+
+ return s;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/dup.c b/src/unistd/dup.c
new file mode 100644
index 00000000..badc0f86
--- /dev/null
+++ b/src/unistd/dup.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "fcntl.h"
+
+int dup(int fildes)
+{
+ return fcntl(fildes, F_DUPFD, 0);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/dup2.c b/src/unistd/dup2.c
new file mode 100644
index 00000000..2755fbc7
--- /dev/null
+++ b/src/unistd/dup2.c
@@ -0,0 +1,29 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "fcntl.h"
+#include "limits.h"
+#include "errno.h"
+
+int dup2(int fildes, int fildes2)
+{
+ if (fildes2 < 0 || fildes2 >= _POSIX_OPEN_MAX) {
+ errno = EBADF;
+ return -1;
+ }
+
+ if (fildes == fildes2) {
+ return fildes2;
+ }
+
+ if (fcntl(fildes, F_GETFD) == -1) {
+ errno = EBADF;
+ return -1;
+ }
+
+ close(fildes2);
+ return fcntl(fildes, F_DUPFD, fildes2);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/execl.c b/src/unistd/execl.c
new file mode 100644
index 00000000..4bfcdd9b
--- /dev/null
+++ b/src/unistd/execl.c
@@ -0,0 +1,24 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "limits.h"
+#include "stdarg.h"
+
+int execl(const char *path, const char *arg0, ... /*, (char *)0 */)
+{
+ char *argv[_POSIX_ARG_MAX], *arg = (char*)arg0;
+ int argc = 0;
+
+ va_list ap;
+ va_start(ap, arg0);
+ do {
+ argv[argc++] = arg;
+ } while ((arg = va_arg(ap, char *)) != NULL);
+ va_end(ap);
+
+ argv[argc] = NULL;
+ return execv(path, argv);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/execle.c b/src/unistd/execle.c
new file mode 100644
index 00000000..d1f42a36
--- /dev/null
+++ b/src/unistd/execle.c
@@ -0,0 +1,26 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "limits.h"
+#include "stdarg.h"
+
+int execle(const char *path, const char *arg0, ... /*, (char *)0, char *const envp[] */)
+{
+ char *argv[_POSIX_ARG_MAX], *arg = (char*)arg0;
+ char **envp = NULL;
+ int argc = 0;
+
+ va_list ap;
+ va_start(ap, arg0);
+ do {
+ argv[argc++] = arg;
+ } while ((arg = va_arg(ap, char *)) != NULL);
+ envp = va_arg(ap, char **);
+ va_end(ap);
+
+ argv[argc] = NULL;
+ return execve(path, argv, envp);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/execlp.c b/src/unistd/execlp.c
new file mode 100644
index 00000000..55d779eb
--- /dev/null
+++ b/src/unistd/execlp.c
@@ -0,0 +1,24 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "stdarg.h"
+#include "limits.h"
+
+int execlp(const char *file, const char *arg0, ... /*, (char *0) */)
+{
+ char *argv[_POSIX_ARG_MAX], *arg = (char*)arg0;
+ int argc = 0;
+
+ va_list ap;
+ va_start(ap, arg0);
+ do {
+ argv[argc++] = arg;
+ } while ((arg = va_arg(ap, char *)) != NULL);
+ va_end(ap);
+
+ argv[argc] = NULL;
+ return execvp(file, argv);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/execv.c b/src/unistd/execv.c
new file mode 100644
index 00000000..3b3e29fb
--- /dev/null
+++ b/src/unistd/execv.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+int execv(const char *path, char *const argv[])
+{
+ extern char **environ;
+ return execve(path, argv, environ);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/execve.c b/src/unistd/execve.c
new file mode 100644
index 00000000..7d54ec91
--- /dev/null
+++ b/src/unistd/execve.c
@@ -0,0 +1,14 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+int execve(const char *path, char *const argv[], char *const envp[])
+{
+ SCNO(scno, "execve", -1);
+ errno = -__libc.syscall(scno, path, argv, envp);
+ return -1;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/execvp.c b/src/unistd/execvp.c
new file mode 100644
index 00000000..5ad54781
--- /dev/null
+++ b/src/unistd/execvp.c
@@ -0,0 +1,20 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+
+int execvp(const char *file, char *const argv[])
+{
+ extern char **environ;
+ /* search $PATH for file */
+ execve(file, argv, environ);
+ if (errno == ENOEXEC) {
+ /* stuff /bin/sh in front */
+ char sh[] = "/bin/sh";
+ return execve(sh, argv, environ);
+ }
+ return -1;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/fork.c b/src/unistd/fork.c
new file mode 100644
index 00000000..3da5c822
--- /dev/null
+++ b/src/unistd/fork.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+
+pid_t fork(void)
+{
+ SC0(pid_t);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/fpathconf.c b/src/unistd/fpathconf.c
new file mode 100644
index 00000000..37fcf41a
--- /dev/null
+++ b/src/unistd/fpathconf.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+long fpathconf(int fildes, int name)
+{
+ (void)fildes; (void)name;
+ return 0;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c
new file mode 100644
index 00000000..e8e46a60
--- /dev/null
+++ b/src/unistd/getcwd.c
@@ -0,0 +1,21 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/assert.h"
+#include "nonstd/syscall.h"
+
+char * getcwd(char *buf, size_t size)
+{
+ ASSERT_NONNULL(buf);
+ SCNO(scno, "getcwd", NULL);
+ int r = __libc.syscall(scno, buf, size);
+ if (r < 0) {
+ errno = -r;
+ return NULL;
+ }
+ return buf;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getegid.c b/src/unistd/getegid.c
new file mode 100644
index 00000000..617e3b70
--- /dev/null
+++ b/src/unistd/getegid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+gid_t getegid(void)
+{
+ SCNOFAIL();
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/geteuid.c b/src/unistd/geteuid.c
new file mode 100644
index 00000000..6ff0d186
--- /dev/null
+++ b/src/unistd/geteuid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+uid_t geteuid(void)
+{
+ SCNOFAIL();
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getgid.c b/src/unistd/getgid.c
new file mode 100644
index 00000000..03c5f62b
--- /dev/null
+++ b/src/unistd/getgid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+gid_t getgid(void)
+{
+ SCNOFAIL();
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getgroups.c b/src/unistd/getgroups.c
new file mode 100644
index 00000000..1e1dd584
--- /dev/null
+++ b/src/unistd/getgroups.c
@@ -0,0 +1,17 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+#include "nonstd/assert.h"
+
+int getgroups(int gidsetsize, gid_t grouplist[])
+{
+ if (gidsetsize != 0) {
+ ASSERT_NONNULL(grouplist);
+ }
+ SC(int, gidsetsize, grouplist);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getlogin.c b/src/unistd/getlogin.c
new file mode 100644
index 00000000..462b5a6d
--- /dev/null
+++ b/src/unistd/getlogin.c
@@ -0,0 +1,11 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+char * getlogin(void)
+{
+ return 0;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getpgrp.c b/src/unistd/getpgrp.c
new file mode 100644
index 00000000..fd079ff1
--- /dev/null
+++ b/src/unistd/getpgrp.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+pid_t getpgrp(void)
+{
+ SCNOFAIL();
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getpid.c b/src/unistd/getpid.c
new file mode 100644
index 00000000..333735b2
--- /dev/null
+++ b/src/unistd/getpid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+pid_t getpid(void)
+{
+ SCNOFAIL();
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getppid.c b/src/unistd/getppid.c
new file mode 100644
index 00000000..d0518c3e
--- /dev/null
+++ b/src/unistd/getppid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+pid_t getppid(void)
+{
+ SCNOFAIL();
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/getuid.c b/src/unistd/getuid.c
new file mode 100644
index 00000000..8a06b900
--- /dev/null
+++ b/src/unistd/getuid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+uid_t getuid(void)
+{
+ SCNOFAIL();
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/isatty.c b/src/unistd/isatty.c
new file mode 100644
index 00000000..baafa508
--- /dev/null
+++ b/src/unistd/isatty.c
@@ -0,0 +1,19 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+
+int isatty(int fildes)
+{
+ SCNO(scno, "isatty", 0);
+ int r = __libc.syscall(scno, fildes);
+ if (r < 0) {
+ errno = -r;
+ return 0;
+ }
+ return r;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/link.c b/src/unistd/link.c
new file mode 100644
index 00000000..8960d1f1
--- /dev/null
+++ b/src/unistd/link.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+int link(const char *path1, const char *path2)
+{
+ SC(int, path1, path2);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/lseek.c b/src/unistd/lseek.c
new file mode 100644
index 00000000..86436a9e
--- /dev/null
+++ b/src/unistd/lseek.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+off_t lseek(int fildes, off_t offset, int whence)
+{
+ SC(off_t, fildes, offset, whence);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/pathconf.c b/src/unistd/pathconf.c
new file mode 100644
index 00000000..c871970e
--- /dev/null
+++ b/src/unistd/pathconf.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+long pathconf(const char *path, int name)
+{
+ (void)path; (void)name;
+ return 0;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/pause.c b/src/unistd/pause.c
new file mode 100644
index 00000000..4ce5771c
--- /dev/null
+++ b/src/unistd/pause.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+
+int pause(void)
+{
+ SC0(int);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/pipe.c b/src/unistd/pipe.c
new file mode 100644
index 00000000..0ceb1181
--- /dev/null
+++ b/src/unistd/pipe.c
@@ -0,0 +1,14 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/assert.h"
+#include "nonstd/syscall.h"
+
+int pipe(int fildes[2])
+{
+ ASSERT_NONNULL(fildes);
+ SC(int, fildes);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/read.c b/src/unistd/read.c
new file mode 100644
index 00000000..dd82ce9c
--- /dev/null
+++ b/src/unistd/read.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+
+ssize_t read(int fildes, void *buf, size_t nbyte)
+{
+ SC(ssize_t, fildes, buf, nbyte);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/rmdir.c b/src/unistd/rmdir.c
new file mode 100644
index 00000000..2991dcbb
--- /dev/null
+++ b/src/unistd/rmdir.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+
+int rmdir(const char *path)
+{
+ SC(int, path);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/setgid.c b/src/unistd/setgid.c
new file mode 100644
index 00000000..947df23e
--- /dev/null
+++ b/src/unistd/setgid.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+
+int setgid(gid_t gid)
+{
+ SC(int, gid);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/setpgid.c b/src/unistd/setpgid.c
new file mode 100644
index 00000000..561dadf0
--- /dev/null
+++ b/src/unistd/setpgid.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "errno.h"
+#include "nonstd/syscall.h"
+
+int setpgid(pid_t pid, pid_t pgid)
+{
+ SC(int, pid, pgid);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/setsid.c b/src/unistd/setsid.c
new file mode 100644
index 00000000..5c39fe0a
--- /dev/null
+++ b/src/unistd/setsid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+pid_t setsid(void)
+{
+ SC0(pid_t);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/setuid.c b/src/unistd/setuid.c
new file mode 100644
index 00000000..ce08fcef
--- /dev/null
+++ b/src/unistd/setuid.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+int setuid(uid_t uid)
+{
+ SC(int, uid);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/sleep.c b/src/unistd/sleep.c
new file mode 100644
index 00000000..1e884f8e
--- /dev/null
+++ b/src/unistd/sleep.c
@@ -0,0 +1,16 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/syscall.h"
+
+unsigned sleep(unsigned seconds)
+{
+ #if 0
+ SC(unsigned, seconds);
+ #else
+ return seconds;
+ #endif
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/sysconf.c b/src/unistd/sysconf.c
new file mode 100644
index 00000000..100dab5b
--- /dev/null
+++ b/src/unistd/sysconf.c
@@ -0,0 +1,11 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+long sysconf(int name)
+{
+ return name;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/tcgetpgrp.c b/src/unistd/tcgetpgrp.c
new file mode 100644
index 00000000..13610d63
--- /dev/null
+++ b/src/unistd/tcgetpgrp.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+pid_t tcgetpgrp(int fildes)
+{
+ (void)fildes;
+ return 0;
+}
+
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/tcsetpgrp.c b/src/unistd/tcsetpgrp.c
new file mode 100644
index 00000000..e3cfe023
--- /dev/null
+++ b/src/unistd/tcsetpgrp.c
@@ -0,0 +1,13 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+int tcsetpgrp(int fildes, pid_t pgid_id)
+{
+ (void)fildes; (void)pgid_id;
+ return 0;
+}
+
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/ttyname.c b/src/unistd/ttyname.c
new file mode 100644
index 00000000..2d4e3cab
--- /dev/null
+++ b/src/unistd/ttyname.c
@@ -0,0 +1,12 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+
+char *ttyname(int fildes)
+{
+ (void)fildes;
+ return NULL;
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/unlink.c b/src/unistd/unlink.c
new file mode 100644
index 00000000..38279888
--- /dev/null
+++ b/src/unistd/unlink.c
@@ -0,0 +1,14 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/assert.h"
+#include "nonstd/syscall.h"
+
+int unlink(const char *path)
+{
+ ASSERT_NONNULL(path);
+ SC(int, path);
+}
+/*
+POSIX(1)
+*/
diff --git a/src/unistd/write.c b/src/unistd/write.c
new file mode 100644
index 00000000..c591c279
--- /dev/null
+++ b/src/unistd/write.c
@@ -0,0 +1,16 @@
+#include "stddef.h"
+#include "sys/types.h"
+#include <unistd.h>
+#include "nonstd/assert.h"
+#include "nonstd/syscall.h"
+
+ssize_t write(int fildes, const void *buf, size_t nbyte)
+{
+ if (nbyte != 0) {
+ ASSERT_NONNULL(buf);
+ }
+ SC(ssize_t, fildes, buf, nbyte);
+}
+/*
+POSIX(1)
+*/