aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2022-12-14 22:12:20 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2022-12-14 22:12:20 +0100
commit7536d000ac9a5188378f2749ecfd7f0ccb437573 (patch)
treee19b0da62b826dd9c6a7b0425ac3ec568a0fe434 /lib
parentd179f1846f9372920ef02f08cfb4d3abe99b383f (diff)
first try to pipe stuff
Diffstat (limited to 'lib')
-rw-r--r--lib/sys/close.h11
-rw-r--r--lib/sys/dup2.h11
-rw-r--r--lib/sys/exit.h11
-rw-r--r--lib/sys/fork.h10
-rw-r--r--lib/sys/io.h11
-rw-r--r--lib/sys/pipe.h14
-rw-r--r--lib/sys/wait4.h12
-rw-r--r--lib/sys/write.h2
8 files changed, 81 insertions, 1 deletions
diff --git a/lib/sys/close.h b/lib/sys/close.h
new file mode 100644
index 0000000..2aa3a71
--- /dev/null
+++ b/lib/sys/close.h
@@ -0,0 +1,11 @@
+#ifndef CLOSE_H
+#define CLOSE_H
+
+#include "syscalls.h"
+
+int close(unsigned int fd)
+{
+ syscall(CLOSE, fd);
+}
+
+#endif
diff --git a/lib/sys/dup2.h b/lib/sys/dup2.h
new file mode 100644
index 0000000..7726efb
--- /dev/null
+++ b/lib/sys/dup2.h
@@ -0,0 +1,11 @@
+#ifndef DUP2_H
+#define DUP2_H
+
+#include "syscalls.h"
+
+int dup2(unsigned int oldfd, unsigned int newfd)
+{
+ return syscall(DUP2, oldfd, newfd);
+}
+
+#endif
diff --git a/lib/sys/exit.h b/lib/sys/exit.h
new file mode 100644
index 0000000..516d714
--- /dev/null
+++ b/lib/sys/exit.h
@@ -0,0 +1,11 @@
+#ifndef EXIT_H
+#define EXIT_H
+
+#include "syscalls.h"
+
+_Noreturn void exit(int error_code)
+{
+ syscall(EXIT, error_code);
+}
+
+#endif
diff --git a/lib/sys/fork.h b/lib/sys/fork.h
new file mode 100644
index 0000000..2ee3ae8
--- /dev/null
+++ b/lib/sys/fork.h
@@ -0,0 +1,10 @@
+#ifndef FORK_H
+#define FORK_H
+
+#include "syscalls.h"
+
+int fork() {
+ return syscall(FORK);
+}
+
+#endif
diff --git a/lib/sys/io.h b/lib/sys/io.h
new file mode 100644
index 0000000..3048ebe
--- /dev/null
+++ b/lib/sys/io.h
@@ -0,0 +1,11 @@
+#ifndef IO_H
+#define IO_H
+
+#include "write.h"
+#include "read.h"
+
+#define STDIN_FD 0
+#define STDOUT_FD 1
+#define STDERR_FD 2
+
+#endif
diff --git a/lib/sys/pipe.h b/lib/sys/pipe.h
new file mode 100644
index 0000000..f95f366
--- /dev/null
+++ b/lib/sys/pipe.h
@@ -0,0 +1,14 @@
+#ifndef PIPE_H
+#define PIPE_H
+
+#include "syscalls.h"
+
+#define PIPE_IN 1
+#define PIPE_OUT 0
+
+int pipe(int *filedes)
+{
+ return syscall(PIPE, filedes);
+}
+
+#endif
diff --git a/lib/sys/wait4.h b/lib/sys/wait4.h
new file mode 100644
index 0000000..e70539e
--- /dev/null
+++ b/lib/sys/wait4.h
@@ -0,0 +1,12 @@
+#ifndef WAIT4_H
+#define WAIT4_H
+
+#include "syscall.h"
+#include "sizes.h"
+
+int wait4(u64 pid, int *stat_addr, int options)
+{
+ return syscall(WAIT4, pid, stat_addr, options);
+}
+
+#endif
diff --git a/lib/sys/write.h b/lib/sys/write.h
index a705873..59f7789 100644
--- a/lib/sys/write.h
+++ b/lib/sys/write.h
@@ -4,7 +4,7 @@
#include "syscalls.h"
static int write(unsigned int fd, const char * buf, unsigned long count) {
- return syscall((void*)WRITE, (void*)fd, (void*)buf, (void*)count);
+ return syscall(WRITE, fd, buf, count);
}
#endif