From b48327d357e0818d1a6ae2a064cfa7d1567e1242 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sun, 5 Dec 2021 15:17:44 -0800 Subject: feat(huge): huge refactor (in progress). Commented out libc includes to uncover all explicit dependencies. A large fraction has now been ported over (no testing). I did not port over the command line tools, such as the rc shell. These will be done independently - as of now I just want the library to stand independent. Compilation currently fails due to the lack of math functions. --- sys/linux/amd64/arch/constants.h | 2 -- sys/linux/port/os/constants.h | 7 +++++++ sys/linux/src/access.c | 7 +++++++ sys/linux/src/accessat.c | 8 ++++++++ sys/linux/src/cwd.c | 8 ++++++++ sys/linux/src/openat.c | 8 ++++++++ sys/linux/src/read.c | 2 +- sys/linux/src/write.c | 2 +- 8 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 sys/linux/src/access.c create mode 100644 sys/linux/src/accessat.c create mode 100644 sys/linux/src/cwd.c create mode 100644 sys/linux/src/openat.c (limited to 'sys/linux') diff --git a/sys/linux/amd64/arch/constants.h b/sys/linux/amd64/arch/constants.h index 1949bdf..f1c1b4c 100644 --- a/sys/linux/amd64/arch/constants.h +++ b/sys/linux/amd64/arch/constants.h @@ -19,5 +19,3 @@ #define sys·ONoATime 01000000 #define sys·OPath 010000000 #define sys·OTempFile 020200000 - -#define SYS·HAVE_FCNTL diff --git a/sys/linux/port/os/constants.h b/sys/linux/port/os/constants.h index f994a93..03bab2a 100644 --- a/sys/linux/port/os/constants.h +++ b/sys/linux/port/os/constants.h @@ -1,5 +1,12 @@ #pragma once +/* file access */ +#define sys·FileExists 0 +#define sys·FileCanExec 1 +#define sys·FileCanWrite 2 +#define sys·FileCanRead 4 + + /* device modes */ #define sys·ModeFile 0170000 #define sys·ModeDir 0040000 diff --git a/sys/linux/src/access.c b/sys/linux/src/access.c new file mode 100644 index 0000000..fc83b55 --- /dev/null +++ b/sys/linux/src/access.c @@ -0,0 +1,7 @@ +#include "internal.h" + +int +sys·access(char *path, int mode) +{ + return sys·accessat(sys·FdCwd, path, mode, 0); +} diff --git a/sys/linux/src/accessat.c b/sys/linux/src/accessat.c new file mode 100644 index 0000000..ba1362f --- /dev/null +++ b/sys/linux/src/accessat.c @@ -0,0 +1,8 @@ +#include "internal.h" + +int +sys·accessat(int dirfd, char *path, int mode, int flags) +{ + long ret = syscall(·FAccessAt2, path, mode, flags); + return error(ret); +} diff --git a/sys/linux/src/cwd.c b/sys/linux/src/cwd.c new file mode 100644 index 0000000..0d8f3c3 --- /dev/null +++ b/sys/linux/src/cwd.c @@ -0,0 +1,8 @@ +#include "internal.h" + +int +sys·cwd(char *buf, uintptr size) +{ + long ret = syscall(·GetCwd, buf, size); + return error(ret); +} diff --git a/sys/linux/src/openat.c b/sys/linux/src/openat.c new file mode 100644 index 0000000..7db7844 --- /dev/null +++ b/sys/linux/src/openat.c @@ -0,0 +1,8 @@ +#include "internal.h" + +int +sys·openat(int dirfd, char *path, int flags, int mode, int *fd) +{ + long ret = *fd = syscall(·OpenAt, dirfd, path, flags, mode); + return error(ret); +} diff --git a/sys/linux/src/read.c b/sys/linux/src/read.c index db9cabf..1ca1a85 100644 --- a/sys/linux/src/read.c +++ b/sys/linux/src/read.c @@ -1,7 +1,7 @@ #include "internal.h" int -sys·read(int fd, uintptr len, void *buf, intptr *n) +sys·read(int fd, void *buf, uintptr len, intptr *n) { intptr ret = *n = syscall(·Read, fd, buf, len); return error(ret); diff --git a/sys/linux/src/write.c b/sys/linux/src/write.c index 4e09d82..9586b93 100644 --- a/sys/linux/src/write.c +++ b/sys/linux/src/write.c @@ -1,7 +1,7 @@ #include "internal.h" int -sys·write(int fd, uintptr len, void *buf, intptr *ret) +sys·write(int fd, void *buf, uintptr len, intptr *ret) { long err = *ret = syscall(·Write, fd, buf, len); return error(err); -- cgit v1.2.1