diff options
Diffstat (limited to 'libc-top-half/musl/src/fcntl')
-rw-r--r-- | libc-top-half/musl/src/fcntl/creat.c | 8 | ||||
-rw-r--r-- | libc-top-half/musl/src/fcntl/fcntl.c | 48 | ||||
-rw-r--r-- | libc-top-half/musl/src/fcntl/open.c | 23 | ||||
-rw-r--r-- | libc-top-half/musl/src/fcntl/openat.c | 19 | ||||
-rw-r--r-- | libc-top-half/musl/src/fcntl/posix_fadvise.c | 18 | ||||
-rw-r--r-- | libc-top-half/musl/src/fcntl/posix_fallocate.c | 10 |
6 files changed, 126 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/fcntl/creat.c b/libc-top-half/musl/src/fcntl/creat.c new file mode 100644 index 0000000..8f8aab6 --- /dev/null +++ b/libc-top-half/musl/src/fcntl/creat.c @@ -0,0 +1,8 @@ +#include <fcntl.h> + +int creat(const char *filename, mode_t mode) +{ + return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode); +} + +weak_alias(creat, creat64); diff --git a/libc-top-half/musl/src/fcntl/fcntl.c b/libc-top-half/musl/src/fcntl/fcntl.c new file mode 100644 index 0000000..d3bff5c --- /dev/null +++ b/libc-top-half/musl/src/fcntl/fcntl.c @@ -0,0 +1,48 @@ +#define _GNU_SOURCE +#include <fcntl.h> +#include <stdarg.h> +#include <errno.h> +#include "syscall.h" + +int fcntl(int fd, int cmd, ...) +{ + unsigned long arg; + va_list ap; + va_start(ap, cmd); + arg = va_arg(ap, unsigned long); + va_end(ap); + if (cmd == F_SETFL) arg |= O_LARGEFILE; + if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg); + if (cmd == F_GETOWN) { + struct f_owner_ex ex; + int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex); + if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg); + if (ret) return __syscall_ret(ret); + return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid; + } + if (cmd == F_DUPFD_CLOEXEC) { + int ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, arg); + if (ret != -EINVAL) { + if (ret >= 0) + __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); + return __syscall_ret(ret); + } + ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, 0); + if (ret != -EINVAL) { + if (ret >= 0) __syscall(SYS_close, ret); + return __syscall_ret(-EINVAL); + } + ret = __syscall(SYS_fcntl, fd, F_DUPFD, arg); + if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); + return __syscall_ret(ret); + } + switch (cmd) { + case F_SETLK: + case F_GETLK: + case F_GETOWN_EX: + case F_SETOWN_EX: + return syscall(SYS_fcntl, fd, cmd, (void *)arg); + default: + return syscall(SYS_fcntl, fd, cmd, arg); + } +} diff --git a/libc-top-half/musl/src/fcntl/open.c b/libc-top-half/musl/src/fcntl/open.c new file mode 100644 index 0000000..1d817a2 --- /dev/null +++ b/libc-top-half/musl/src/fcntl/open.c @@ -0,0 +1,23 @@ +#include <fcntl.h> +#include <stdarg.h> +#include "syscall.h" + +int open(const char *filename, int flags, ...) +{ + mode_t mode = 0; + + if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + + int fd = __sys_open_cp(filename, flags, mode); + if (fd>=0 && (flags & O_CLOEXEC)) + __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); + + return __syscall_ret(fd); +} + +weak_alias(open, open64); diff --git a/libc-top-half/musl/src/fcntl/openat.c b/libc-top-half/musl/src/fcntl/openat.c new file mode 100644 index 0000000..ad165ec --- /dev/null +++ b/libc-top-half/musl/src/fcntl/openat.c @@ -0,0 +1,19 @@ +#include <fcntl.h> +#include <stdarg.h> +#include "syscall.h" + +int openat(int fd, const char *filename, int flags, ...) +{ + mode_t mode = 0; + + if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + + return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode); +} + +weak_alias(openat, openat64); diff --git a/libc-top-half/musl/src/fcntl/posix_fadvise.c b/libc-top-half/musl/src/fcntl/posix_fadvise.c new file mode 100644 index 0000000..75b8e1a --- /dev/null +++ b/libc-top-half/musl/src/fcntl/posix_fadvise.c @@ -0,0 +1,18 @@ +#include <fcntl.h> +#include "syscall.h" + +int posix_fadvise(int fd, off_t base, off_t len, int advice) +{ +#if defined(SYSCALL_FADVISE_6_ARG) + /* Some archs, at least arm and powerpc, have the syscall + * arguments reordered to avoid needing 7 argument registers + * due to 64-bit argument alignment. */ + return -__syscall(SYS_fadvise, fd, advice, + __SYSCALL_LL_E(base), __SYSCALL_LL_E(len)); +#else + return -__syscall(SYS_fadvise, fd, __SYSCALL_LL_O(base), + __SYSCALL_LL_E(len), advice); +#endif +} + +weak_alias(posix_fadvise, posix_fadvise64); diff --git a/libc-top-half/musl/src/fcntl/posix_fallocate.c b/libc-top-half/musl/src/fcntl/posix_fallocate.c new file mode 100644 index 0000000..c57a24a --- /dev/null +++ b/libc-top-half/musl/src/fcntl/posix_fallocate.c @@ -0,0 +1,10 @@ +#include <fcntl.h> +#include "syscall.h" + +int posix_fallocate(int fd, off_t base, off_t len) +{ + return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base), + __SYSCALL_LL_E(len)); +} + +weak_alias(posix_fallocate, posix_fallocate64); |