From 4e09bca9e34c226b6d7e34b4fa11248405fd988e Mon Sep 17 00:00:00 2001 From: Anton Kling Date: Sun, 22 Oct 2023 19:50:38 +0200 Subject: Move everything into a new repo. --- userland/libc/unistd/_exit.c | 8 ++++++++ userland/libc/unistd/execvp.c | 8 ++++++++ userland/libc/unistd/getopt.c | 14 ++++++++++++++ userland/libc/unistd/getpid.c | 7 +++++++ userland/libc/unistd/msleep.c | 6 ++++++ userland/libc/unistd/unlink.c | 7 +++++++ userland/libc/unistd/uptime.c | 6 ++++++ 7 files changed, 56 insertions(+) create mode 100644 userland/libc/unistd/_exit.c create mode 100644 userland/libc/unistd/execvp.c create mode 100644 userland/libc/unistd/getopt.c create mode 100644 userland/libc/unistd/getpid.c create mode 100644 userland/libc/unistd/msleep.c create mode 100644 userland/libc/unistd/unlink.c create mode 100644 userland/libc/unistd/uptime.c (limited to 'userland/libc/unistd') diff --git a/userland/libc/unistd/_exit.c b/userland/libc/unistd/_exit.c new file mode 100644 index 0000000..c6d64be --- /dev/null +++ b/userland/libc/unistd/_exit.c @@ -0,0 +1,8 @@ +#include +#include + +// FIXME: Technically exit and _exit are different but this +// stackoverflow answer says that it does not usually matter. So lets +// hope that is the case. +// https://stackoverflow.com/a/5423108 +void _exit(int status) { syscall(SYS_EXIT, (void *)status, 0, 0, 0, 0); } diff --git a/userland/libc/unistd/execvp.c b/userland/libc/unistd/execvp.c new file mode 100644 index 0000000..573e822 --- /dev/null +++ b/userland/libc/unistd/execvp.c @@ -0,0 +1,8 @@ +#include +#include + +// FIXME: Path resolution +int execvp(const char *file, char *const argv[]) { + struct SYS_EXEC_PARAMS args = {.path = file, .argv = argv}; + return syscall(SYS_EXEC, &args, 0, 0, 0, 0); +} diff --git a/userland/libc/unistd/getopt.c b/userland/libc/unistd/getopt.c new file mode 100644 index 0000000..a026b59 --- /dev/null +++ b/userland/libc/unistd/getopt.c @@ -0,0 +1,14 @@ +#include +#include + +int opterr, optind, optopt; +char *optarg; + +// https://pubs.opengroup.org/onlinepubs/9699919799/functions/getopt.html +int getopt(int argc, char *const argv[], const char *optstring) { + // TODO + optind = 1; + optarg = NULL; + // assert(0); + return -1; +} diff --git a/userland/libc/unistd/getpid.c b/userland/libc/unistd/getpid.c new file mode 100644 index 0000000..8aeef10 --- /dev/null +++ b/userland/libc/unistd/getpid.c @@ -0,0 +1,7 @@ +#include +#include +#include + +pid_t getpid(void) { + return s_syscall(SYS_GETPID); +} diff --git a/userland/libc/unistd/msleep.c b/userland/libc/unistd/msleep.c new file mode 100644 index 0000000..0b016c6 --- /dev/null +++ b/userland/libc/unistd/msleep.c @@ -0,0 +1,6 @@ +// Not standard, but it feels like it should be. +#include +#include +#include + +void msleep(uint32_t ms) { syscall(SYS_MSLEEP, (void *)ms, 0, 0, 0, 0); } diff --git a/userland/libc/unistd/unlink.c b/userland/libc/unistd/unlink.c new file mode 100644 index 0000000..ccac0df --- /dev/null +++ b/userland/libc/unistd/unlink.c @@ -0,0 +1,7 @@ +#include + +int unlink(const char *path) { + // TODO + printf("TODO: Implement unlink"); + return 0; +} diff --git a/userland/libc/unistd/uptime.c b/userland/libc/unistd/uptime.c new file mode 100644 index 0000000..090a0e5 --- /dev/null +++ b/userland/libc/unistd/uptime.c @@ -0,0 +1,6 @@ +// Not standard, but it feels like it should be. +#include +#include +#include + +uint32_t uptime(void) { return syscall(SYS_UPTIME, 0, 0, 0, 0, 0); } -- cgit v1.2.3