diff options
| author | Jakob Kaivo <jkk@ung.org> | 2019-02-09 13:14:01 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2019-02-09 13:14:01 -0500 |
| commit | 253a32e2f9ff1cbb8edbe7c79834a678daebeb93 (patch) | |
| tree | 599cf5baf01c6dae33a2f89989b08b7d553f7fd0 /src/fcntl | |
| parent | 88d0b5e7ffbf0554b236dc46225846061b5f4817 (diff) | |
merge POSIX.1-1988/1990
Diffstat (limited to 'src/fcntl')
| -rw-r--r-- | src/fcntl/FD_CLOEXEC.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_DUPFD.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_GETFD.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_GETFL.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_GETLK.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_RDLCK.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_SETFD.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_SETFL.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_SETLK.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_SETLKW.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_UNLCK.c | 7 | ||||
| -rw-r--r-- | src/fcntl/F_WRLCK.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_ACCMODE.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_APPEND.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_CREAT.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_EXCL.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_NOCTTY.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_NONBLOCK.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_RDONLY.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_RDWR.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_TRUNC.c | 7 | ||||
| -rw-r--r-- | src/fcntl/O_WRONLY.c | 7 | ||||
| -rw-r--r-- | src/fcntl/creat.c | 11 | ||||
| -rw-r--r-- | src/fcntl/fcntl.c | 61 | ||||
| -rw-r--r-- | src/fcntl/open.c | 30 | ||||
| -rw-r--r-- | src/fcntl/struct_flock.c | 13 |
26 files changed, 269 insertions, 0 deletions
diff --git a/src/fcntl/FD_CLOEXEC.c b/src/fcntl/FD_CLOEXEC.c new file mode 100644 index 00000000..f406ed34 --- /dev/null +++ b/src/fcntl/FD_CLOEXEC.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define FD_CLOEXEC (1) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_DUPFD.c b/src/fcntl/F_DUPFD.c new file mode 100644 index 00000000..e0428596 --- /dev/null +++ b/src/fcntl/F_DUPFD.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_DUPFD (1) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_GETFD.c b/src/fcntl/F_GETFD.c new file mode 100644 index 00000000..6d99ea3c --- /dev/null +++ b/src/fcntl/F_GETFD.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_GETFD (3) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_GETFL.c b/src/fcntl/F_GETFL.c new file mode 100644 index 00000000..f9432301 --- /dev/null +++ b/src/fcntl/F_GETFL.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_GETFL (5) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_GETLK.c b/src/fcntl/F_GETLK.c new file mode 100644 index 00000000..8236e213 --- /dev/null +++ b/src/fcntl/F_GETLK.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_GETLK (7) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_RDLCK.c b/src/fcntl/F_RDLCK.c new file mode 100644 index 00000000..53fce2a3 --- /dev/null +++ b/src/fcntl/F_RDLCK.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_RDLCK (1) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_SETFD.c b/src/fcntl/F_SETFD.c new file mode 100644 index 00000000..aa0f6070 --- /dev/null +++ b/src/fcntl/F_SETFD.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_SETFD (4) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_SETFL.c b/src/fcntl/F_SETFL.c new file mode 100644 index 00000000..0a40145c --- /dev/null +++ b/src/fcntl/F_SETFL.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_SETFL (6) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_SETLK.c b/src/fcntl/F_SETLK.c new file mode 100644 index 00000000..ccc09f4e --- /dev/null +++ b/src/fcntl/F_SETLK.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_SETLK (8) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_SETLKW.c b/src/fcntl/F_SETLKW.c new file mode 100644 index 00000000..045e5991 --- /dev/null +++ b/src/fcntl/F_SETLKW.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_SETLKW (9) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_UNLCK.c b/src/fcntl/F_UNLCK.c new file mode 100644 index 00000000..42c4c416 --- /dev/null +++ b/src/fcntl/F_UNLCK.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_UNLCK (2) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/F_WRLCK.c b/src/fcntl/F_WRLCK.c new file mode 100644 index 00000000..8eaa8711 --- /dev/null +++ b/src/fcntl/F_WRLCK.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define F_WRLCK (3) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_ACCMODE.c b/src/fcntl/O_ACCMODE.c new file mode 100644 index 00000000..82045649 --- /dev/null +++ b/src/fcntl/O_ACCMODE.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_ACCMODE (O_EXEC|O_RDONLY|O_RDWR|O_SEARCH|O_WRONLY) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_APPEND.c b/src/fcntl/O_APPEND.c new file mode 100644 index 00000000..d6526545 --- /dev/null +++ b/src/fcntl/O_APPEND.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_APPEND (1<<8) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_CREAT.c b/src/fcntl/O_CREAT.c new file mode 100644 index 00000000..03d04b91 --- /dev/null +++ b/src/fcntl/O_CREAT.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_CREAT (1<<1) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_EXCL.c b/src/fcntl/O_EXCL.c new file mode 100644 index 00000000..144eebbb --- /dev/null +++ b/src/fcntl/O_EXCL.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_EXCL (1<<3) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_NOCTTY.c b/src/fcntl/O_NOCTTY.c new file mode 100644 index 00000000..c7805910 --- /dev/null +++ b/src/fcntl/O_NOCTTY.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_NOCTTY (1<<4) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_NONBLOCK.c b/src/fcntl/O_NONBLOCK.c new file mode 100644 index 00000000..7ccda6ad --- /dev/null +++ b/src/fcntl/O_NONBLOCK.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_NONBLOCK (1<<10) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_RDONLY.c b/src/fcntl/O_RDONLY.c new file mode 100644 index 00000000..00425d4e --- /dev/null +++ b/src/fcntl/O_RDONLY.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_RDONLY (1<<14) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_RDWR.c b/src/fcntl/O_RDWR.c new file mode 100644 index 00000000..f1ce88b2 --- /dev/null +++ b/src/fcntl/O_RDWR.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_RDWR (1<<15) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_TRUNC.c b/src/fcntl/O_TRUNC.c new file mode 100644 index 00000000..d835021a --- /dev/null +++ b/src/fcntl/O_TRUNC.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_TRUNC (1<<6) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/O_WRONLY.c b/src/fcntl/O_WRONLY.c new file mode 100644 index 00000000..e6c00841 --- /dev/null +++ b/src/fcntl/O_WRONLY.c @@ -0,0 +1,7 @@ +#include <fcntl.h> + +#define O_WRONLY (1<<17) + +/* +POSIX(1) +*/ diff --git a/src/fcntl/creat.c b/src/fcntl/creat.c new file mode 100644 index 00000000..eab98ca8 --- /dev/null +++ b/src/fcntl/creat.c @@ -0,0 +1,11 @@ +#include "sys/types.h" +#include <fcntl.h> + +int creat(const char *path, mode_t mode) +{ + return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode); +} + +/* +POSIX(1) +*/ diff --git a/src/fcntl/fcntl.c b/src/fcntl/fcntl.c new file mode 100644 index 00000000..18288776 --- /dev/null +++ b/src/fcntl/fcntl.c @@ -0,0 +1,61 @@ +#include "sys/types.h" +#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); + + int r = -ENOSYS; + enum { NONE, INT, FLOCK } arg = NONE; + + switch (cmd) { + case F_GETFD: + case F_GETFL: + break; + + case F_DUPFD: + case F_SETFD: + case F_SETFL: + arg = INT; + break; + + case F_GETLK: + case F_SETLK: + case F_SETLKW: + arg = FLOCK; + break; + + default: + errno = EINVAL; + return -1; + } + + if (arg == NONE) { + r = __libc.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); + } else if (arg == FLOCK) { + struct flock *fl = va_arg(ap, struct flock *); + r = __libc.syscall(scno, fildes, fl); + } + va_end(ap); + } + + if (r < 0) { + errno = -r; + return -1; + } + + return r; +} +/* +POSIX(1) +*/ diff --git a/src/fcntl/open.c b/src/fcntl/open.c new file mode 100644 index 00000000..f0968556 --- /dev/null +++ b/src/fcntl/open.c @@ -0,0 +1,30 @@ +#include "sys/types.h" +#include <fcntl.h> +#include "sys/stat.h" /* OH */ +#include "errno.h" +#include "stdarg.h" +#include "nonstd/syscall.h" + +int open(const char *path, int oflag, ...) +{ + SCNO(scno, "open", -1); + + mode_t mode = 0; + if (oflag & O_CREAT) { + va_list ap; + va_start(ap, oflag); + mode = va_arg(ap, mode_t); + va_end(ap); + } + + int r = __libc.syscall(scno, path, oflag, mode); + if (r < 0) { + errno = -r; + return -1; + } + + return r; +} +/* +POSIX(1) +*/ diff --git a/src/fcntl/struct_flock.c b/src/fcntl/struct_flock.c new file mode 100644 index 00000000..c910e0ff --- /dev/null +++ b/src/fcntl/struct_flock.c @@ -0,0 +1,13 @@ +#include <fcntl.h> + +struct flock { + short l_type; + short l_whence; + off_t l_start; + off_t l_len; + pid_t l_pid; +}; + +/* +POSIX(1) +*/ |
