diff options
49 files changed, 82 insertions, 77 deletions
diff --git a/src/dirent/closedir.c b/src/dirent/closedir.c index daa72d50..60ea8a57 100644 --- a/src/dirent/closedir.c +++ b/src/dirent/closedir.c @@ -1,19 +1,11 @@ #include <dirent.h> #include "nonstd/assert.h" -#include "nonstd/types.h" #include "nonstd/syscall.h" int closedir(DIR *dirp) { ASSERT_NONNULL(dirp); - SCNO(scno, "closedir", -1); - - int r = __libc.syscall(scno, dirp); - if (r < 0) { - errno = -r; - return -1; - } - return 0; + SYSCALL("closedir", int, -1, dirp, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/fcntl/fcntl.c b/src/fcntl/fcntl.c index 18288776..b02745e9 100644 --- a/src/fcntl/fcntl.c +++ b/src/fcntl/fcntl.c @@ -2,12 +2,11 @@ #include <fcntl.h> #include "errno.h" #include "stdarg.h" -#include "nonstd/types.h" #include "nonstd/syscall.h" int fcntl(int fildes, int cmd, ...) { - SCNO(scno, "fcntl", -1); + SYSCALL_NUMBER(scno, "fcntl", -1); int r = -ENOSYS; enum { NONE, INT, FLOCK } arg = NONE; @@ -35,16 +34,16 @@ int fcntl(int fildes, int cmd, ...) } if (arg == NONE) { - r = __libc.syscall(scno, fildes); + r = __syscall(scno, fildes); } else { va_list ap; va_start(ap, cmd); if (arg == INT) { int n = va_arg(ap, int); - r = __libc.syscall(scno, fildes, n); + r = __syscall(scno, fildes, n); } else if (arg == FLOCK) { struct flock *fl = va_arg(ap, struct flock *); - r = __libc.syscall(scno, fildes, fl); + r = __syscall(scno, fildes, fl); } va_end(ap); } diff --git a/src/fcntl/open.c b/src/fcntl/open.c index f0968556..07bf7f6d 100644 --- a/src/fcntl/open.c +++ b/src/fcntl/open.c @@ -7,7 +7,7 @@ int open(const char *path, int oflag, ...) { - SCNO(scno, "open", -1); + SYSCALL_NUMBER(scno, "open", -1); mode_t mode = 0; if (oflag & O_CREAT) { @@ -17,7 +17,7 @@ int open(const char *path, int oflag, ...) va_end(ap); } - int r = __libc.syscall(scno, path, oflag, mode); + int r = __syscall(scno, path, oflag, mode); if (r < 0) { errno = -r; return -1; diff --git a/src/fnmatch/fnmatch.c b/src/fnmatch/fnmatch.c index d7cb9856..4e566524 100644 --- a/src/fnmatch/fnmatch.c +++ b/src/fnmatch/fnmatch.c @@ -1,11 +1,11 @@ #include <fnmatch.h> -#include "__nonstd.h" +#include "nonstd/assert.h" int fnmatch(const char * pattern, const char * string, int flags) { - __ASSERT_NONNULL(pattern); - __ASSERT_NONNULL(string); - // __ASSERT_FLAGS(flags, FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD); + ASSERT_NONNULL(pattern); + ASSERT_NONNULL(string); + /* __ASSERT_FLAGS(flags, FNM_PATHNAME | FNM_NOESCAPE | FNM_PERIOD); */ const char *ppos = pattern; const char *spos = string; diff --git a/src/glob/glob.c b/src/glob/glob.c index 15e30731..e8e6b8a6 100644 --- a/src/glob/glob.c +++ b/src/glob/glob.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <glob.h> #include "stdlib.h" #include "string.h" @@ -5,14 +6,18 @@ #include "fnmatch.h" #include "errno.h" #include "unistd.h" -#include "__nonstd.h" +#include "nonstd/assert.h" int glob(const char * restrict pattern, int flags, int (*errfunc) (const char * epath, int eerrno), glob_t * restrict pglob) { - __ASSERT_NONNULL(pattern); - __ASSERT_NONNULL(pglob); + ASSERT_NONNULL(pattern); + ASSERT_NONNULL(pglob); + + int slashes = 0; + size_t i; int fnmatch_flags = FNM_PATHNAME | FNM_PERIOD; + if (flags & GLOB_NOESCAPE) { fnmatch_flags |= FNM_NOESCAPE; } @@ -32,9 +37,8 @@ int glob(const char * restrict pattern, int flags, int (*errfunc) (const char * } char *path = strdup(pattern); - int slashes = 0; - for (size_t i = 0; path[i]; i++) { + for (i = 0; path[i]; i++) { if (path[i] == '/') { slashes++; path[i] = '\0'; diff --git a/src/glob/globfree.c b/src/glob/globfree.c index f04708c4..228dcea8 100644 --- a/src/glob/globfree.c +++ b/src/glob/globfree.c @@ -1,13 +1,16 @@ +#include "sys/types.h" #include <glob.h> #include "stdlib.h" void globfree(glob_t * pglob) { + size_t i; + if (pglob == NULL) { return; } - for (size_t i = 0; i < pglob->gl_pathc; i++) { + for (i = 0; i < pglob->gl_pathc; i++) { if (pglob->gl_pathv[i] != NULL) { free(pglob->gl_pathv[i]); } diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c index 9c3585b1..8dc2aa8d 100644 --- a/src/regex/regcomp.c +++ b/src/regex/regcomp.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <regex.h> int regcomp(regex_t * restrict preg, const char * restrict pattern, int cflags) diff --git a/src/regex/regerror.c b/src/regex/regerror.c index 6c11fb3b..49d7a28e 100644 --- a/src/regex/regerror.c +++ b/src/regex/regerror.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <regex.h> size_t regerror(int errcode, const regex_t * restrict preg, char * restrict errbuf, size_t errbuf_size) diff --git a/src/regex/regexec.c b/src/regex/regexec.c index d749c257..1051f732 100644 --- a/src/regex/regexec.c +++ b/src/regex/regexec.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <regex.h> int regexec(const regex_t * restrict preg, const char * restrict string, size_t nmatch, regmatch_t pmatch[restrict], int eflags) diff --git a/src/regex/regfree.c b/src/regex/regfree.c index 14395e6a..34cbb379 100644 --- a/src/regex/regfree.c +++ b/src/regex/regfree.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <regex.h> void regfree(regex_t * preg) diff --git a/src/signal/kill.c b/src/signal/kill.c index 78c3d3ef..05949d52 100644 --- a/src/signal/kill.c +++ b/src/signal/kill.c @@ -4,7 +4,7 @@ int kill(pid_t pid, int sig) { - SC(int, pid, sig); + SYSCALL("kill", int, -1, pid, sig, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/signal/signal.c b/src/signal/signal.c index 373fddc5..eac3b650 100644 --- a/src/signal/signal.c +++ b/src/signal/signal.c @@ -1,4 +1,4 @@ -#if defined _POSIX_SOURCE +#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE #include "sys/types.h" #endif diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c index e8cd037e..f07cf55e 100644 --- a/src/stdio/fclose.c +++ b/src/stdio/fclose.c @@ -2,7 +2,8 @@ #include "stdlib.h" #include "nonstd/io.h" -#ifdef _POSIX_SOURCE +#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE +#include "sys/types.h" #include "unistd.h" #else #define close(fd) -1 diff --git a/src/stdio/fileno.c b/src/stdio/fileno.c index a3af0ec2..56ba86aa 100644 --- a/src/stdio/fileno.c +++ b/src/stdio/fileno.c @@ -1,5 +1,5 @@ #include <stdio.h> -#include "nonstd/FILE.h" +#include "nonstd/io.h" #include "nonstd/assert.h" int fileno(FILE * stream) diff --git a/src/stdio/fputc.c b/src/stdio/fputc.c index eb249b77..7b80f0ef 100644 --- a/src/stdio/fputc.c +++ b/src/stdio/fputc.c @@ -1,7 +1,8 @@ #include <stdio.h> #include "nonstd/io.h" -#ifdef _POSIX_SOURCE +#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE +#include "sys/types.h" #include "unistd.h" #else #define write(fd, buf, size) -1 diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c index cddf296a..69732a48 100644 --- a/src/stdio/freopen.c +++ b/src/stdio/freopen.c @@ -2,7 +2,8 @@ #include "errno.h" #include "nonstd/io.h" -#ifdef _POSIX_SOURCE +#if defined _POSIX_SOURCE || defined _POSIX_C_SOURCE || defined _XOPEN_SOURCE +#include "sys/types.h" #include "fcntl.h" #else #define open(fname, flags, mode) (filename ? -1 : -1) diff --git a/src/stdio/pclose.c b/src/stdio/pclose.c index 7a70bf9f..aff03b73 100644 --- a/src/stdio/pclose.c +++ b/src/stdio/pclose.c @@ -1,5 +1,7 @@ #include <stdio.h> +#include "sys/types.h" #include "sys/wait.h" +#include "nonstd/io.h" int pclose(FILE * stream) { @@ -11,7 +13,7 @@ int pclose(FILE * stream) fclose(stream); - waitpid(pid, &status, 0); + waitpid(child, &status, 0); return status; } diff --git a/src/stdio/popen.c b/src/stdio/popen.c index cd1a6572..56fce132 100644 --- a/src/stdio/popen.c +++ b/src/stdio/popen.c @@ -1,14 +1,17 @@ #include <stdio.h> #include "string.h" #include "errno.h" + +#include "sys/types.h" #include "unistd.h" -#include "wchar.h" -#include "__nonstd.h" + +#include "nonstd/assert.h" +#include "nonstd/io.h" FILE * popen(const char * command, const char * mode) { - __ASSERT_NONNULL(command); - __ASSERT_NONNULL(mode); + ASSERT_NONNULL(command); + ASSERT_NONNULL(mode); int direction = 0; if (!strcmp(mode, "w")) { @@ -52,7 +55,7 @@ FILE * popen(const char * command, const char * mode) } fwide(p, -1); - p->pipe_pid = pid; + p->pipe_pid = child; return p; } diff --git a/src/termios/cfsetispeed.c b/src/termios/cfsetispeed.c index 40267942..f2452171 100644 --- a/src/termios/cfsetispeed.c +++ b/src/termios/cfsetispeed.c @@ -1,4 +1,5 @@ #include <termios.h> +#include "errno.h" #include "nonstd/assert.h" int cfsetispeed(struct termios *termios_p, speed_t speed) diff --git a/src/termios/cfsetospeed.c b/src/termios/cfsetospeed.c index 93e53c61..af99a0bb 100644 --- a/src/termios/cfsetospeed.c +++ b/src/termios/cfsetospeed.c @@ -1,4 +1,5 @@ #include <termios.h> +#include "errno.h" #include "nonstd/assert.h" int cfsetospeed(struct termios *termios_p, speed_t speed) diff --git a/src/unistd/_exit.c b/src/unistd/_exit.c index fde6d675..4f1ef7e6 100644 --- a/src/unistd/_exit.c +++ b/src/unistd/_exit.c @@ -5,7 +5,7 @@ void _exit(int status) { - __libc.syscall(__libc.syscall_lookup("exit"), status); + __syscall(((syscall_lookup_t)__libc(SYSCALL_LOOKUP))("exit"), status); for (;;); } /* diff --git a/src/unistd/chdir.c b/src/unistd/chdir.c index 82dc997a..828487d3 100644 --- a/src/unistd/chdir.c +++ b/src/unistd/chdir.c @@ -5,7 +5,7 @@ int chdir(const char *path) { - SC(int, path); + SYSCALL("chdir", int, -1, path, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/chown.c b/src/unistd/chown.c index 55b32b07..08c52364 100644 --- a/src/unistd/chown.c +++ b/src/unistd/chown.c @@ -5,7 +5,7 @@ int chown(const char *path, uid_t owner, gid_t group) { - SC(int, path, owner, group); + SYSCALL("chown", int, -1, path, owner, group, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/close.c b/src/unistd/close.c index b4f402eb..3744aa86 100644 --- a/src/unistd/close.c +++ b/src/unistd/close.c @@ -5,7 +5,7 @@ int close(int fildes) { - SC(int, fildes); + SYSCALL("close", int, -1, fildes, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/confstr.c b/src/unistd/confstr.c index a0f57b30..0cf00319 100644 --- a/src/unistd/confstr.c +++ b/src/unistd/confstr.c @@ -1,13 +1,15 @@ +#include "sys/types.h" #include <unistd.h> #include "errno.h" #include "string.h" +#include "nonstd/assert.h" size_t confstr(int name, char *buf, size_t len) { char *value = NULL; if (len > 0) { - __ASSERT_NONNULL(buf); + ASSERT_NONNULL(buf); } switch (name) { diff --git a/src/unistd/execve.c b/src/unistd/execve.c index 7d54ec91..8d7a1225 100644 --- a/src/unistd/execve.c +++ b/src/unistd/execve.c @@ -5,8 +5,8 @@ int execve(const char *path, char *const argv[], char *const envp[]) { - SCNO(scno, "execve", -1); - errno = -__libc.syscall(scno, path, argv, envp); + SYSCALL_NUMBER(scno, "execve", -1); + errno = -__syscall(scno, path, argv, envp); return -1; } /* diff --git a/src/unistd/fork.c b/src/unistd/fork.c index 3da5c822..4efcc0f4 100644 --- a/src/unistd/fork.c +++ b/src/unistd/fork.c @@ -6,7 +6,7 @@ pid_t fork(void) { - SC0(pid_t); + SYSCALL("fork", pid_t, -1, 0, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c index e8e46a60..904e2c7d 100644 --- a/src/unistd/getcwd.c +++ b/src/unistd/getcwd.c @@ -1,20 +1,12 @@ -#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; + SYSCALL("getcwd", char *, NULL, buf, size, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/getgroups.c b/src/unistd/getgroups.c index 1e1dd584..8af2634b 100644 --- a/src/unistd/getgroups.c +++ b/src/unistd/getgroups.c @@ -10,7 +10,7 @@ int getgroups(int gidsetsize, gid_t grouplist[]) if (gidsetsize != 0) { ASSERT_NONNULL(grouplist); } - SC(int, gidsetsize, grouplist); + SYSCALL("getgroups", int, -1, gidsetsize, grouplist, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/getopt.c b/src/unistd/getopt.c index 29fe5590..dc1803dd 100644 --- a/src/unistd/getopt.c +++ b/src/unistd/getopt.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include "string.h" #include "stdio.h" #include <unistd.h> diff --git a/src/unistd/isatty.c b/src/unistd/isatty.c index baafa508..1b502d75 100644 --- a/src/unistd/isatty.c +++ b/src/unistd/isatty.c @@ -6,13 +6,7 @@ int isatty(int fildes) { - SCNO(scno, "isatty", 0); - int r = __libc.syscall(scno, fildes); - if (r < 0) { - errno = -r; - return 0; - } - return r; + SYSCALL("isatty", int, -1, fildes, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/link.c b/src/unistd/link.c index 8960d1f1..96e1e7b4 100644 --- a/src/unistd/link.c +++ b/src/unistd/link.c @@ -5,7 +5,7 @@ int link(const char *path1, const char *path2) { - SC(int, path1, path2); + SYSCALL("link", int, -1, path1, path2, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/lseek.c b/src/unistd/lseek.c index 86436a9e..dd194761 100644 --- a/src/unistd/lseek.c +++ b/src/unistd/lseek.c @@ -5,7 +5,7 @@ off_t lseek(int fildes, off_t offset, int whence) { - SC(off_t, fildes, offset, whence); + SYSCALL("lseek", off_t, -1, fildes, offset, whence, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/optarg.c b/src/unistd/optarg.c index be7407c1..8eddca9d 100644 --- a/src/unistd/optarg.c +++ b/src/unistd/optarg.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <unistd.h> char * optarg; /* diff --git a/src/unistd/opterr.c b/src/unistd/opterr.c index f5e831e4..68d44563 100644 --- a/src/unistd/opterr.c +++ b/src/unistd/opterr.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <unistd.h> int opterr; /* diff --git a/src/unistd/optind.c b/src/unistd/optind.c index 8cd6e14b..b6cff979 100644 --- a/src/unistd/optind.c +++ b/src/unistd/optind.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <unistd.h> int optind; /* diff --git a/src/unistd/optopt.c b/src/unistd/optopt.c index 7ab8471c..797f4fd9 100644 --- a/src/unistd/optopt.c +++ b/src/unistd/optopt.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <unistd.h> int optopt; /* diff --git a/src/unistd/pause.c b/src/unistd/pause.c index 4ce5771c..41e25101 100644 --- a/src/unistd/pause.c +++ b/src/unistd/pause.c @@ -1,12 +1,11 @@ #include "stddef.h" #include "sys/types.h" #include <unistd.h> -#include "errno.h" #include "nonstd/syscall.h" int pause(void) { - SC0(int); + SYSCALL("pause", int, -1, 0, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/pipe.c b/src/unistd/pipe.c index 0ceb1181..5ab8b5e7 100644 --- a/src/unistd/pipe.c +++ b/src/unistd/pipe.c @@ -7,7 +7,7 @@ int pipe(int fildes[2]) { ASSERT_NONNULL(fildes); - SC(int, fildes); + SYSCALL("pipe", int, -1, fildes, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/read.c b/src/unistd/read.c index dd82ce9c..c44e406d 100644 --- a/src/unistd/read.c +++ b/src/unistd/read.c @@ -6,7 +6,7 @@ ssize_t read(int fildes, void *buf, size_t nbyte) { - SC(ssize_t, fildes, buf, nbyte); + SYSCALL("read", ssize_t, -1, fildes, buf, nbyte, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/rmdir.c b/src/unistd/rmdir.c index 2991dcbb..6c6df741 100644 --- a/src/unistd/rmdir.c +++ b/src/unistd/rmdir.c @@ -6,7 +6,7 @@ int rmdir(const char *path) { - SC(int, path); + SYSCALL("rmdir", int, -1, path, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/setgid.c b/src/unistd/setgid.c index 947df23e..79f9695b 100644 --- a/src/unistd/setgid.c +++ b/src/unistd/setgid.c @@ -1,12 +1,11 @@ #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); + SYSCALL("setgid", int, -1, gid, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/setpgid.c b/src/unistd/setpgid.c index 561dadf0..28769713 100644 --- a/src/unistd/setpgid.c +++ b/src/unistd/setpgid.c @@ -6,7 +6,7 @@ int setpgid(pid_t pid, pid_t pgid) { - SC(int, pid, pgid); + SYSCALL("setpgid", int, -1, pid, pgid, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/setsid.c b/src/unistd/setsid.c index 5c39fe0a..8c1aa0c7 100644 --- a/src/unistd/setsid.c +++ b/src/unistd/setsid.c @@ -5,7 +5,7 @@ pid_t setsid(void) { - SC0(pid_t); + SYSCALL("setsid", pid_t, -1, 0, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/setuid.c b/src/unistd/setuid.c index ce08fcef..4c6053df 100644 --- a/src/unistd/setuid.c +++ b/src/unistd/setuid.c @@ -5,7 +5,7 @@ int setuid(uid_t uid) { - SC(int, uid); + SYSCALL("setuid", int, -1, uid, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/unlink.c b/src/unistd/unlink.c index 38279888..09fc20b0 100644 --- a/src/unistd/unlink.c +++ b/src/unistd/unlink.c @@ -7,7 +7,7 @@ int unlink(const char *path) { ASSERT_NONNULL(path); - SC(int, path); + SYSCALL("unlink", int, -1, path, 0, 0, 0, 0, 0); } /* POSIX(1) diff --git a/src/unistd/write.c b/src/unistd/write.c index c591c279..352ef43f 100644 --- a/src/unistd/write.c +++ b/src/unistd/write.c @@ -9,7 +9,7 @@ ssize_t write(int fildes, const void *buf, size_t nbyte) if (nbyte != 0) { ASSERT_NONNULL(buf); } - SC(ssize_t, fildes, buf, nbyte); + SYSCALL("write", ssize_t, -1, fildes, buf, nbyte, 0, 0, 0); } /* POSIX(1) diff --git a/src/wordexp/wordexp.c b/src/wordexp/wordexp.c index 5ac38d9e..4a81db03 100644 --- a/src/wordexp/wordexp.c +++ b/src/wordexp/wordexp.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <wordexp.h> int wordexp(const char *restrict words, wordexp_t *restrict pwordexp, int flags) diff --git a/src/wordexp/wordfree.c b/src/wordexp/wordfree.c index f1043c2d..096de4be 100644 --- a/src/wordexp/wordfree.c +++ b/src/wordexp/wordfree.c @@ -1,3 +1,4 @@ +#include "sys/types.h" #include <wordexp.h> void wordfree(wordexp_t *pwordexp) |
