summaryrefslogtreecommitdiff
path: root/userland/libc/unistd
diff options
context:
space:
mode:
Diffstat (limited to 'userland/libc/unistd')
-rw-r--r--userland/libc/unistd/_exit.c8
-rw-r--r--userland/libc/unistd/execvp.c8
-rw-r--r--userland/libc/unistd/getopt.c14
-rw-r--r--userland/libc/unistd/getpid.c7
-rw-r--r--userland/libc/unistd/msleep.c6
-rw-r--r--userland/libc/unistd/unlink.c7
-rw-r--r--userland/libc/unistd/uptime.c6
7 files changed, 56 insertions, 0 deletions
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 <syscall.h>
+#include <unistd.h>
+
+// 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 <unistd.h>
+#include <syscall.h>
+
+// 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 <assert.h>
+#include <unistd.h>
+
+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 <unistd.h>
+#include <syscall.h>
+#include <sys/types.h>
+
+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 <syscall.h>
+#include <unistd.h>
+#include <stdint.h>
+
+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 <unistd.h>
+
+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 <stdint.h>
+#include <syscall.h>
+#include <unistd.h>
+
+uint32_t uptime(void) { return syscall(SYS_UPTIME, 0, 0, 0, 0, 0); }