From 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 12 Feb 2011 00:22:29 -0500 Subject: initial check-in, version 0.5.0 --- src/unistd/_exit.c | 7 +++++++ src/unistd/access.c | 7 +++++++ src/unistd/alarm.c | 7 +++++++ src/unistd/chdir.c | 7 +++++++ src/unistd/chown.c | 7 +++++++ src/unistd/close.c | 11 +++++++++++ src/unistd/confstr.c | 17 +++++++++++++++++ src/unistd/ctermid.c | 23 +++++++++++++++++++++++ src/unistd/dup.c | 7 +++++++ src/unistd/dup2.c | 7 +++++++ src/unistd/faccessat.c | 7 +++++++ src/unistd/fchdir.c | 7 +++++++ src/unistd/fchown.c | 7 +++++++ src/unistd/fchownat.c | 7 +++++++ src/unistd/fdatasync.c | 7 +++++++ src/unistd/fsync.c | 8 ++++++++ src/unistd/ftruncate.c | 15 +++++++++++++++ src/unistd/getcwd.c | 8 ++++++++ src/unistd/getegid.c | 7 +++++++ src/unistd/geteuid.c | 7 +++++++ src/unistd/getgid.c | 7 +++++++ src/unistd/getgroups.c | 8 ++++++++ src/unistd/gethostname.c | 14 ++++++++++++++ src/unistd/getlogin.c | 7 +++++++ src/unistd/getlogin_r.c | 13 +++++++++++++ src/unistd/getpgid.c | 7 +++++++ src/unistd/getpgrp.c | 7 +++++++ src/unistd/getpid.c | 7 +++++++ src/unistd/getppid.c | 7 +++++++ src/unistd/getsid.c | 7 +++++++ src/unistd/getuid.c | 7 +++++++ src/unistd/isatty.c | 8 ++++++++ src/unistd/lchown.c | 7 +++++++ src/unistd/link.c | 7 +++++++ src/unistd/linkat.c | 7 +++++++ src/unistd/lseek.c | 16 ++++++++++++++++ src/unistd/nice.c | 7 +++++++ src/unistd/pause.c | 12 ++++++++++++ src/unistd/pipe.c | 7 +++++++ src/unistd/pread.c | 14 ++++++++++++++ src/unistd/pwrite.c | 14 ++++++++++++++ src/unistd/read.c | 12 ++++++++++++ src/unistd/readlink.c | 7 +++++++ src/unistd/readlinkat.c | 7 +++++++ src/unistd/readv.c | 12 ++++++++++++ src/unistd/renameat.c | 7 +++++++ src/unistd/rmdir.c | 7 +++++++ src/unistd/setegid.c | 6 ++++++ src/unistd/seteuid.c | 6 ++++++ src/unistd/setgid.c | 9 +++++++++ src/unistd/setpgid.c | 7 +++++++ src/unistd/setpgrp.c | 6 ++++++ src/unistd/setregid.c | 9 +++++++++ src/unistd/setreuid.c | 9 +++++++++ src/unistd/setsid.c | 7 +++++++ src/unistd/setuid.c | 9 +++++++++ src/unistd/sleep.c | 10 ++++++++++ src/unistd/symlink.c | 7 +++++++ src/unistd/symlinkat.c | 7 +++++++ src/unistd/sync.c | 7 +++++++ src/unistd/tcgetpgrp.c | 11 +++++++++++ src/unistd/tcsetpgrp.c | 9 +++++++++ src/unistd/truncate.c | 15 +++++++++++++++ src/unistd/ttyname.c | 14 ++++++++++++++ src/unistd/ttyname_r.c | 19 +++++++++++++++++++ src/unistd/ualarm.c | 8 ++++++++ src/unistd/unlink.c | 7 +++++++ src/unistd/unlinkat.c | 7 +++++++ src/unistd/usleep.c | 11 +++++++++++ src/unistd/write.c | 12 ++++++++++++ src/unistd/writev.c | 12 ++++++++++++ 71 files changed, 646 insertions(+) create mode 100644 src/unistd/_exit.c create mode 100644 src/unistd/access.c create mode 100644 src/unistd/alarm.c create mode 100644 src/unistd/chdir.c create mode 100644 src/unistd/chown.c create mode 100644 src/unistd/close.c create mode 100644 src/unistd/confstr.c create mode 100644 src/unistd/ctermid.c create mode 100644 src/unistd/dup.c create mode 100644 src/unistd/dup2.c create mode 100644 src/unistd/faccessat.c create mode 100644 src/unistd/fchdir.c create mode 100644 src/unistd/fchown.c create mode 100644 src/unistd/fchownat.c create mode 100644 src/unistd/fdatasync.c create mode 100644 src/unistd/fsync.c create mode 100644 src/unistd/ftruncate.c create mode 100644 src/unistd/getcwd.c create mode 100644 src/unistd/getegid.c create mode 100644 src/unistd/geteuid.c create mode 100644 src/unistd/getgid.c create mode 100644 src/unistd/getgroups.c create mode 100644 src/unistd/gethostname.c create mode 100644 src/unistd/getlogin.c create mode 100644 src/unistd/getlogin_r.c create mode 100644 src/unistd/getpgid.c create mode 100644 src/unistd/getpgrp.c create mode 100644 src/unistd/getpid.c create mode 100644 src/unistd/getppid.c create mode 100644 src/unistd/getsid.c create mode 100644 src/unistd/getuid.c create mode 100644 src/unistd/isatty.c create mode 100644 src/unistd/lchown.c create mode 100644 src/unistd/link.c create mode 100644 src/unistd/linkat.c create mode 100644 src/unistd/lseek.c create mode 100644 src/unistd/nice.c create mode 100644 src/unistd/pause.c create mode 100644 src/unistd/pipe.c create mode 100644 src/unistd/pread.c create mode 100644 src/unistd/pwrite.c create mode 100644 src/unistd/read.c create mode 100644 src/unistd/readlink.c create mode 100644 src/unistd/readlinkat.c create mode 100644 src/unistd/readv.c create mode 100644 src/unistd/renameat.c create mode 100644 src/unistd/rmdir.c create mode 100644 src/unistd/setegid.c create mode 100644 src/unistd/seteuid.c create mode 100644 src/unistd/setgid.c create mode 100644 src/unistd/setpgid.c create mode 100644 src/unistd/setpgrp.c create mode 100644 src/unistd/setregid.c create mode 100644 src/unistd/setreuid.c create mode 100644 src/unistd/setsid.c create mode 100644 src/unistd/setuid.c create mode 100644 src/unistd/sleep.c create mode 100644 src/unistd/symlink.c create mode 100644 src/unistd/symlinkat.c create mode 100644 src/unistd/sync.c create mode 100644 src/unistd/tcgetpgrp.c create mode 100644 src/unistd/tcsetpgrp.c create mode 100644 src/unistd/truncate.c create mode 100644 src/unistd/ttyname.c create mode 100644 src/unistd/ttyname_r.c create mode 100644 src/unistd/ualarm.c create mode 100644 src/unistd/unlink.c create mode 100644 src/unistd/unlinkat.c create mode 100644 src/unistd/usleep.c create mode 100644 src/unistd/write.c create mode 100644 src/unistd/writev.c (limited to 'src/unistd') diff --git a/src/unistd/_exit.c b/src/unistd/_exit.c new file mode 100644 index 00000000..d2e84c4c --- /dev/null +++ b/src/unistd/_exit.c @@ -0,0 +1,7 @@ +#include +#include + +void _exit(int status) +{ + _Exit(status); +} diff --git a/src/unistd/access.c b/src/unistd/access.c new file mode 100644 index 00000000..2c10e58c --- /dev/null +++ b/src/unistd/access.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int access(const char *filename, int amode) +{ + return syscall2(__NR_access, (long)filename, amode); +} diff --git a/src/unistd/alarm.c b/src/unistd/alarm.c new file mode 100644 index 00000000..bba444d8 --- /dev/null +++ b/src/unistd/alarm.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +unsigned alarm(unsigned seconds) +{ + return syscall1(__NR_alarm, seconds); +} diff --git a/src/unistd/chdir.c b/src/unistd/chdir.c new file mode 100644 index 00000000..c89bda38 --- /dev/null +++ b/src/unistd/chdir.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int chdir(const char *path) +{ + return syscall1(__NR_chdir, (long)path); +} diff --git a/src/unistd/chown.c b/src/unistd/chown.c new file mode 100644 index 00000000..6069a2fe --- /dev/null +++ b/src/unistd/chown.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int chown(const char *path, uid_t uid, gid_t gid) +{ + return syscall3(__NR_chown32, (long)path, uid, gid); +} diff --git a/src/unistd/close.c b/src/unistd/close.c new file mode 100644 index 00000000..97302f67 --- /dev/null +++ b/src/unistd/close.c @@ -0,0 +1,11 @@ +#include +#include "syscall.h" +#include "libc.h" + +int close(int fd) +{ + int ret = __syscall_close(fd); + CANCELPT_BEGIN; + CANCELPT_END; + return ret; +} diff --git a/src/unistd/confstr.c b/src/unistd/confstr.c new file mode 100644 index 00000000..4332f726 --- /dev/null +++ b/src/unistd/confstr.c @@ -0,0 +1,17 @@ +#include +#include +#include + +size_t confstr(int name, char *buf, size_t len) +{ + const char *s = ""; + if (!name) { + s = "/bin:/usr/bin"; + } else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>31U) { + errno = EINVAL; + return 0; + } + // snprintf is overkill but avoid wasting code size to implement + // this completely useless function and its truncation semantics + return snprintf(buf, len, "%s", s); +} diff --git a/src/unistd/ctermid.c b/src/unistd/ctermid.c new file mode 100644 index 00000000..21b44ec8 --- /dev/null +++ b/src/unistd/ctermid.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include +#include +#include + +char *ctermid(char *s) +{ + static char *s2; + int fd; + if (!s) { + if (!s2) s2 = malloc(L_ctermid); + s = s2; + } + fd = open("/dev/tty", O_WRONLY | O_NOCTTY); + if (fd < 0) + return strcpy(s, ""); + if (ttyname_r(fd, s, L_ctermid)) + strcpy(s, ""); + close(fd); + return s; +} diff --git a/src/unistd/dup.c b/src/unistd/dup.c new file mode 100644 index 00000000..b11cd715 --- /dev/null +++ b/src/unistd/dup.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int dup(int fd) +{ + return syscall1(__NR_dup, fd); +} diff --git a/src/unistd/dup2.c b/src/unistd/dup2.c new file mode 100644 index 00000000..93325446 --- /dev/null +++ b/src/unistd/dup2.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int dup2(int old, int new) +{ + return __syscall_dup2(old, new); +} diff --git a/src/unistd/faccessat.c b/src/unistd/faccessat.c new file mode 100644 index 00000000..99a93785 --- /dev/null +++ b/src/unistd/faccessat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int faccessat(int fd, const char *filename, int amode, int flag) +{ + return syscall4(__NR_faccessat, fd, (long)filename, amode, flag); +} diff --git a/src/unistd/fchdir.c b/src/unistd/fchdir.c new file mode 100644 index 00000000..b2acbc29 --- /dev/null +++ b/src/unistd/fchdir.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int fchdir(int fd) +{ + return syscall1(__NR_fchdir, fd); +} diff --git a/src/unistd/fchown.c b/src/unistd/fchown.c new file mode 100644 index 00000000..990f006d --- /dev/null +++ b/src/unistd/fchown.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int fchown(int fd, uid_t uid, gid_t gid) +{ + return syscall3(__NR_fchown32, fd, uid, gid); +} diff --git a/src/unistd/fchownat.c b/src/unistd/fchownat.c new file mode 100644 index 00000000..70626428 --- /dev/null +++ b/src/unistd/fchownat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag) +{ + return syscall5(__NR_fchownat, fd, (long)path, uid, gid, flag); +} diff --git a/src/unistd/fdatasync.c b/src/unistd/fdatasync.c new file mode 100644 index 00000000..ef7c9a9d --- /dev/null +++ b/src/unistd/fdatasync.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int fdatasync(int fd) +{ + return 0; +} diff --git a/src/unistd/fsync.c b/src/unistd/fsync.c new file mode 100644 index 00000000..7cfedc98 --- /dev/null +++ b/src/unistd/fsync.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" + +int fsync(int fd) +{ + //return syscall1(__NR_fsync, fd); + return 0; +} diff --git a/src/unistd/ftruncate.c b/src/unistd/ftruncate.c new file mode 100644 index 00000000..e0b2f4bb --- /dev/null +++ b/src/unistd/ftruncate.c @@ -0,0 +1,15 @@ +#include +#include "syscall.h" +#include "libc.h" + +int ftruncate(int fd, off_t length) +{ + if (sizeof(long) == 8) + return syscall2(__NR_ftruncate, fd, length); + else { + union { long long ll; long l[2]; } u = { length }; + return syscall3(__NR_ftruncate64, fd, u.l[0], u.l[1]); + } +} + +LFS64(ftruncate); diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c new file mode 100644 index 00000000..4910f42c --- /dev/null +++ b/src/unistd/getcwd.c @@ -0,0 +1,8 @@ +#include +#include +#include "syscall.h" + +char *getcwd(char *buf, size_t size) +{ + return syscall2(__NR_getcwd, (long)buf, size) < 0 ? NULL : buf; +} diff --git a/src/unistd/getegid.c b/src/unistd/getegid.c new file mode 100644 index 00000000..0e626b75 --- /dev/null +++ b/src/unistd/getegid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +gid_t getegid(void) +{ + return syscall0(__NR_getegid32); +} diff --git a/src/unistd/geteuid.c b/src/unistd/geteuid.c new file mode 100644 index 00000000..39d6ac7b --- /dev/null +++ b/src/unistd/geteuid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +uid_t geteuid(void) +{ + return syscall0(__NR_geteuid32); +} diff --git a/src/unistd/getgid.c b/src/unistd/getgid.c new file mode 100644 index 00000000..186635a2 --- /dev/null +++ b/src/unistd/getgid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +gid_t getgid(void) +{ + return syscall0(__NR_getgid32); +} diff --git a/src/unistd/getgroups.c b/src/unistd/getgroups.c new file mode 100644 index 00000000..6f19870e --- /dev/null +++ b/src/unistd/getgroups.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" + +int getgroups(int count, gid_t list[]) +{ + /* this depends on our gid_t being 32bit */ + return syscall2(__NR_getgroups32, count, (long)list); +} diff --git a/src/unistd/gethostname.c b/src/unistd/gethostname.c new file mode 100644 index 00000000..a406c4eb --- /dev/null +++ b/src/unistd/gethostname.c @@ -0,0 +1,14 @@ +#include +#include +#include + +int gethostname(char *name, size_t len) +{ + size_t i; + struct utsname uts; + if (uname(&uts)) return -1; + if (len > sizeof uts.nodename) len = sizeof uts.nodename; + for (i=0; i +#include + +char *getlogin(void) +{ + return getenv("LOGNAME"); +} diff --git a/src/unistd/getlogin_r.c b/src/unistd/getlogin_r.c new file mode 100644 index 00000000..f04f71e5 --- /dev/null +++ b/src/unistd/getlogin_r.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include + +int getlogin_r(char *name, size_t size) +{ + char *logname = getlogin(); + if (!logname) return ENXIO; /* or...? */ + if (strlen(name) >= size) return ERANGE; + strcpy(name, logname); + return 0; +} diff --git a/src/unistd/getpgid.c b/src/unistd/getpgid.c new file mode 100644 index 00000000..50d716b5 --- /dev/null +++ b/src/unistd/getpgid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getpgid(pid_t pid) +{ + return syscall1(__NR_getpgid, pid); +} diff --git a/src/unistd/getpgrp.c b/src/unistd/getpgrp.c new file mode 100644 index 00000000..2004630a --- /dev/null +++ b/src/unistd/getpgrp.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getpgrp(void) +{ + return syscall0(__NR_getpgrp); +} diff --git a/src/unistd/getpid.c b/src/unistd/getpid.c new file mode 100644 index 00000000..31cbe1cb --- /dev/null +++ b/src/unistd/getpid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getpid(void) +{ + return syscall0(__NR_getpid); +} diff --git a/src/unistd/getppid.c b/src/unistd/getppid.c new file mode 100644 index 00000000..a3241829 --- /dev/null +++ b/src/unistd/getppid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getppid(void) +{ + return syscall0(__NR_getppid); +} diff --git a/src/unistd/getsid.c b/src/unistd/getsid.c new file mode 100644 index 00000000..064229cf --- /dev/null +++ b/src/unistd/getsid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t getsid(pid_t pid) +{ + return syscall1(__NR_getsid, pid); +} diff --git a/src/unistd/getuid.c b/src/unistd/getuid.c new file mode 100644 index 00000000..9d4e53f5 --- /dev/null +++ b/src/unistd/getuid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +uid_t getuid(void) +{ + return syscall0(__NR_getuid32); +} diff --git a/src/unistd/isatty.c b/src/unistd/isatty.c new file mode 100644 index 00000000..cff6e9fe --- /dev/null +++ b/src/unistd/isatty.c @@ -0,0 +1,8 @@ +#include +#include + +int isatty(int fd) +{ + struct termios t; + return tcgetattr(fd, &t) == 0; +} diff --git a/src/unistd/lchown.c b/src/unistd/lchown.c new file mode 100644 index 00000000..30e83916 --- /dev/null +++ b/src/unistd/lchown.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int lchown(const char *path, uid_t uid, gid_t gid) +{ + return syscall3(__NR_lchown32, (long)path, uid, gid); +} diff --git a/src/unistd/link.c b/src/unistd/link.c new file mode 100644 index 00000000..f121bb9e --- /dev/null +++ b/src/unistd/link.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int link(const char *existing, const char *new) +{ + return syscall2(__NR_link, (long)existing, (long)new); +} diff --git a/src/unistd/linkat.c b/src/unistd/linkat.c new file mode 100644 index 00000000..0eb51221 --- /dev/null +++ b/src/unistd/linkat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int linkat(int fd1, const char *existing, int fd2, const char *new, int flag) +{ + return syscall5(__NR_linkat, fd1, (long)existing, fd2, (long)new, flag); +} diff --git a/src/unistd/lseek.c b/src/unistd/lseek.c new file mode 100644 index 00000000..0dab2679 --- /dev/null +++ b/src/unistd/lseek.c @@ -0,0 +1,16 @@ +#include +#include "syscall.h" +#include "libc.h" + +off_t lseek(int fd, off_t offset, int whence) +{ + /* optimized away at compiletime */ + if (sizeof(long) == 8) + return syscall3(__NR_lseek, fd, offset, whence); + else { + off_t result; + return syscall5(__NR__llseek, fd, offset>>32, offset, (long)&result, whence) ? -1 : result; + } +} + +LFS64(lseek); diff --git a/src/unistd/nice.c b/src/unistd/nice.c new file mode 100644 index 00000000..4b28ef41 --- /dev/null +++ b/src/unistd/nice.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int nice(int inc) +{ + return syscall1(__NR_nice, inc); +} diff --git a/src/unistd/pause.c b/src/unistd/pause.c new file mode 100644 index 00000000..14720651 --- /dev/null +++ b/src/unistd/pause.c @@ -0,0 +1,12 @@ +#include +#include "syscall.h" +#include "libc.h" + +int pause(void) +{ + int r; + CANCELPT_BEGIN; + r = syscall0(__NR_pause); + CANCELPT_END; + return r; +} diff --git a/src/unistd/pipe.c b/src/unistd/pipe.c new file mode 100644 index 00000000..2dfc9c99 --- /dev/null +++ b/src/unistd/pipe.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int pipe(int fd[2]) +{ + return syscall1(__NR_pipe, (long)fd); +} diff --git a/src/unistd/pread.c b/src/unistd/pread.c new file mode 100644 index 00000000..029ba3d1 --- /dev/null +++ b/src/unistd/pread.c @@ -0,0 +1,14 @@ +#include +#include "syscall.h" +#include "libc.h" + +ssize_t pread(int fd, void *buf, size_t size, off_t ofs) +{ + ssize_t r; + CANCELPT_BEGIN; + r = syscall5(__NR_pread64, fd, (long)buf, size, SYSCALL_LL(ofs)); + CANCELPT_END; + return r; +} + +LFS64(pread); diff --git a/src/unistd/pwrite.c b/src/unistd/pwrite.c new file mode 100644 index 00000000..8f23d1b9 --- /dev/null +++ b/src/unistd/pwrite.c @@ -0,0 +1,14 @@ +#include +#include "syscall.h" +#include "libc.h" + +ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) +{ + ssize_t r; + CANCELPT_BEGIN; + r = syscall5(__NR_pwrite64, fd, (long)buf, size, SYSCALL_LL(ofs)); + CANCELPT_END; + return r; +} + +LFS64(pwrite); diff --git a/src/unistd/read.c b/src/unistd/read.c new file mode 100644 index 00000000..87ff1f10 --- /dev/null +++ b/src/unistd/read.c @@ -0,0 +1,12 @@ +#include +#include "syscall.h" +#include "libc.h" + +ssize_t read(int fd, void *buf, size_t count) +{ + ssize_t r; + CANCELPT_BEGIN; + r = __syscall_read(fd, buf, count); + CANCELPT_END; + return r; +} diff --git a/src/unistd/readlink.c b/src/unistd/readlink.c new file mode 100644 index 00000000..f6b1635c --- /dev/null +++ b/src/unistd/readlink.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int readlink(const char *path, char *buf, size_t bufsize) +{ + return syscall3(__NR_readlink, (long)path, (long)buf, bufsize); +} diff --git a/src/unistd/readlinkat.c b/src/unistd/readlinkat.c new file mode 100644 index 00000000..8171050d --- /dev/null +++ b/src/unistd/readlinkat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int readlinkat(int fd, const char *path, char *buf, size_t bufsize) +{ + return syscall4(__NR_readlinkat, fd, (long)path, (long)buf, bufsize); +} diff --git a/src/unistd/readv.c b/src/unistd/readv.c new file mode 100644 index 00000000..e311f9de --- /dev/null +++ b/src/unistd/readv.c @@ -0,0 +1,12 @@ +#include +#include "syscall.h" +#include "libc.h" + +ssize_t readv(int fd, const struct iovec *iov, int count) +{ + ssize_t r; + CANCELPT_BEGIN; + r = syscall3(__NR_readv, fd, (long)iov, count); + CANCELPT_END; + return r; +} diff --git a/src/unistd/renameat.c b/src/unistd/renameat.c new file mode 100644 index 00000000..0dae9f11 --- /dev/null +++ b/src/unistd/renameat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int renameat(int oldfd, const char *old, int newfd, const char *new) +{ + return syscall4(__NR_renameat, oldfd, (long)old, newfd, (long)new); +} diff --git a/src/unistd/rmdir.c b/src/unistd/rmdir.c new file mode 100644 index 00000000..8e18c7a8 --- /dev/null +++ b/src/unistd/rmdir.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int rmdir(const char *path) +{ + return syscall1(__NR_rmdir, (long)path); +} diff --git a/src/unistd/setegid.c b/src/unistd/setegid.c new file mode 100644 index 00000000..85348842 --- /dev/null +++ b/src/unistd/setegid.c @@ -0,0 +1,6 @@ +#include + +int setegid(gid_t egid) +{ + return setregid(-1, egid); +} diff --git a/src/unistd/seteuid.c b/src/unistd/seteuid.c new file mode 100644 index 00000000..0aaa86e0 --- /dev/null +++ b/src/unistd/seteuid.c @@ -0,0 +1,6 @@ +#include + +int seteuid(uid_t euid) +{ + return setreuid(-1, euid); +} diff --git a/src/unistd/setgid.c b/src/unistd/setgid.c new file mode 100644 index 00000000..00c7a03a --- /dev/null +++ b/src/unistd/setgid.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setgid(gid_t gid) +{ + if (libc.rsyscall) return libc.rsyscall(__NR_setgid32, gid, 0, 0, 0, 0, 0); + return syscall1(__NR_setgid32, gid); +} diff --git a/src/unistd/setpgid.c b/src/unistd/setpgid.c new file mode 100644 index 00000000..748d2907 --- /dev/null +++ b/src/unistd/setpgid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t setpgid(pid_t pid, pid_t pgid) +{ + return syscall2(__NR_setpgid, pid, pgid); +} diff --git a/src/unistd/setpgrp.c b/src/unistd/setpgrp.c new file mode 100644 index 00000000..a2a37f65 --- /dev/null +++ b/src/unistd/setpgrp.c @@ -0,0 +1,6 @@ +#include + +pid_t setpgrp(void) +{ + return setpgid(0, 0); +} diff --git a/src/unistd/setregid.c b/src/unistd/setregid.c new file mode 100644 index 00000000..d25dab76 --- /dev/null +++ b/src/unistd/setregid.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setregid(gid_t rgid, gid_t egid) +{ + if (libc.rsyscall) return libc.rsyscall(__NR_setregid32, rgid, egid, 0, 0, 0, 0); + return syscall2(__NR_setregid32, rgid, egid); +} diff --git a/src/unistd/setreuid.c b/src/unistd/setreuid.c new file mode 100644 index 00000000..0ba2277b --- /dev/null +++ b/src/unistd/setreuid.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setreuid(uid_t ruid, uid_t euid) +{ + if (libc.rsyscall) return libc.rsyscall(__NR_setreuid32, ruid, euid, 0, 0, 0, 0); + return syscall2(__NR_setreuid32, ruid, euid); +} diff --git a/src/unistd/setsid.c b/src/unistd/setsid.c new file mode 100644 index 00000000..e2c5690c --- /dev/null +++ b/src/unistd/setsid.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +pid_t setsid(void) +{ + return syscall0(__NR_setsid); +} diff --git a/src/unistd/setuid.c b/src/unistd/setuid.c new file mode 100644 index 00000000..53b74d88 --- /dev/null +++ b/src/unistd/setuid.c @@ -0,0 +1,9 @@ +#include +#include "syscall.h" +#include "libc.h" + +int setuid(uid_t uid) +{ + if (libc.rsyscall) return libc.rsyscall(__NR_setuid32, uid, 0, 0, 0, 0, 0); + return syscall1(__NR_setuid32, uid); +} diff --git a/src/unistd/sleep.c b/src/unistd/sleep.c new file mode 100644 index 00000000..d6450941 --- /dev/null +++ b/src/unistd/sleep.c @@ -0,0 +1,10 @@ +#include +#include + +unsigned sleep(unsigned seconds) +{ + struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 }; + if (nanosleep(&tv, &tv)) + return tv.tv_sec; + return 0; +} diff --git a/src/unistd/symlink.c b/src/unistd/symlink.c new file mode 100644 index 00000000..8d380d85 --- /dev/null +++ b/src/unistd/symlink.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int symlink(const char *existing, const char *new) +{ + return syscall2(__NR_symlink, (long)existing, (long)new); +} diff --git a/src/unistd/symlinkat.c b/src/unistd/symlinkat.c new file mode 100644 index 00000000..9693b226 --- /dev/null +++ b/src/unistd/symlinkat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int symlinkat(const char *existing, int fd, const char *new) +{ + return syscall3(__NR_symlinkat, (long)existing, fd, (long)new); +} diff --git a/src/unistd/sync.c b/src/unistd/sync.c new file mode 100644 index 00000000..a49808fd --- /dev/null +++ b/src/unistd/sync.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +void sync(void) +{ + syscall0(__NR_sync); +} diff --git a/src/unistd/tcgetpgrp.c b/src/unistd/tcgetpgrp.c new file mode 100644 index 00000000..50080c7e --- /dev/null +++ b/src/unistd/tcgetpgrp.c @@ -0,0 +1,11 @@ +#include +#include +#include + +pid_t tcgetpgrp(int fd) +{ + int pgrp; + if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) + return -1; + return pgrp; +} diff --git a/src/unistd/tcsetpgrp.c b/src/unistd/tcsetpgrp.c new file mode 100644 index 00000000..67c38cb4 --- /dev/null +++ b/src/unistd/tcsetpgrp.c @@ -0,0 +1,9 @@ +#include +#include +#include + +int tcsetpgrp(int fd, pid_t pgrp) +{ + int pgrp_int = pgrp; + return ioctl(fd, TIOCSPGRP, &pgrp_int); +} diff --git a/src/unistd/truncate.c b/src/unistd/truncate.c new file mode 100644 index 00000000..f75e824e --- /dev/null +++ b/src/unistd/truncate.c @@ -0,0 +1,15 @@ +#include +#include "syscall.h" +#include "libc.h" + +int truncate(const char *path, off_t length) +{ + if (sizeof(long) == 8) + return syscall2(__NR_truncate, (long)path, length); + else { + union { long long ll; long l[2]; } u = { length }; + return syscall3(__NR_truncate64, (long)path, u.l[0], u.l[1]); + } +} + +LFS64(truncate); diff --git a/src/unistd/ttyname.c b/src/unistd/ttyname.c new file mode 100644 index 00000000..0f3e1141 --- /dev/null +++ b/src/unistd/ttyname.c @@ -0,0 +1,14 @@ +#include +#include +#include + +char *ttyname(int fd) +{ + static char buf[TTY_NAME_MAX]; + int result; + if ((result = ttyname_r(fd, buf, sizeof buf))) { + errno = result; + return NULL; + } + return buf; +} diff --git a/src/unistd/ttyname_r.c b/src/unistd/ttyname_r.c new file mode 100644 index 00000000..f86fbd9c --- /dev/null +++ b/src/unistd/ttyname_r.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include + +int ttyname_r(int fd, char *name, size_t size) +{ + char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; + ssize_t l; + + if (!isatty(fd)) return ENOTTY; + + snprintf(procname, sizeof procname, "/proc/self/fd/%d", fd); + l = readlink(procname, name, size); + + if (l < 0) return errno; + else if (l == size) return ERANGE; + else return 0; +} diff --git a/src/unistd/ualarm.c b/src/unistd/ualarm.c new file mode 100644 index 00000000..be853035 --- /dev/null +++ b/src/unistd/ualarm.c @@ -0,0 +1,8 @@ +#include +#include "syscall.h" + +/* FIXME: ?? */ +useconds_t ualarm(useconds_t useconds, useconds_t interval) +{ + return -1; +} diff --git a/src/unistd/unlink.c b/src/unistd/unlink.c new file mode 100644 index 00000000..fb577920 --- /dev/null +++ b/src/unistd/unlink.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int unlink(const char *path) +{ + return __syscall_unlink(path); +} diff --git a/src/unistd/unlinkat.c b/src/unistd/unlinkat.c new file mode 100644 index 00000000..47fccc17 --- /dev/null +++ b/src/unistd/unlinkat.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +int unlinkat(int fd, const char *path, int flag) +{ + return syscall3(__NR_unlinkat, fd, (long)path, flag); +} diff --git a/src/unistd/usleep.c b/src/unistd/usleep.c new file mode 100644 index 00000000..e3869017 --- /dev/null +++ b/src/unistd/usleep.c @@ -0,0 +1,11 @@ +#include +#include + +int usleep(useconds_t useconds) +{ + struct timespec tv = { + .tv_sec = useconds/1000000, + .tv_nsec = (useconds%1000000)*1000 + }; + return nanosleep(&tv, &tv); +} diff --git a/src/unistd/write.c b/src/unistd/write.c new file mode 100644 index 00000000..426cfc5b --- /dev/null +++ b/src/unistd/write.c @@ -0,0 +1,12 @@ +#include +#include "syscall.h" +#include "libc.h" + +ssize_t write(int fd, const void *buf, size_t count) +{ + int r; + CANCELPT_BEGIN; + r = __syscall_write(fd, buf, count); + CANCELPT_END; + return r; +} diff --git a/src/unistd/writev.c b/src/unistd/writev.c new file mode 100644 index 00000000..a6a118af --- /dev/null +++ b/src/unistd/writev.c @@ -0,0 +1,12 @@ +#include +#include "syscall.h" +#include "libc.h" + +ssize_t writev(int fd, const struct iovec *iov, int count) +{ + ssize_t r; + CANCELPT_BEGIN; + r = syscall3(__NR_writev, fd, (long)iov, count); + CANCELPT_END; + return r; +} -- cgit v1.2.1