aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/exec/exec.c38
-rw-r--r--lib/exec/exec.h6
-rw-r--r--lib/sys/unmount.h11
3 files changed, 55 insertions, 0 deletions
diff --git a/lib/exec/exec.c b/lib/exec/exec.c
new file mode 100644
index 0000000..42fd2c1
--- /dev/null
+++ b/lib/exec/exec.c
@@ -0,0 +1,38 @@
+#include "exec.h"
+#include "../sys/execve.h"
+#include "../env/env.h"
+#include "../cstr/cstr.h"
+#include "../malloc/malloc.h"
+
+int exec(const char **argv)
+{
+ const char *path = getenv("PATH");
+ const char *end;
+ char *filename;
+
+ while (*path) {
+ end = path;
+
+ while (*end && *end != ':') ++end;
+
+ filename = malloc((end - path) + cstr_length(argv[0]) + 2);
+
+ for (int i = 0; i < end - path; ++i)
+ filename[i] = path[i];
+
+ filename[end - path] = '/';
+
+ for (int i = 0; i < cstr_length(argv[0]) + 1; ++i)
+ filename[(end - path) + i + 1] = argv[0][i];
+
+ execve(filename, argv, getenvp());
+ free(filename);
+
+ path = end;
+
+ if (*path == ':')
+ ++path;
+ }
+
+ return execve(argv[0], argv, getenvp());
+}
diff --git a/lib/exec/exec.h b/lib/exec/exec.h
new file mode 100644
index 0000000..fe7e811
--- /dev/null
+++ b/lib/exec/exec.h
@@ -0,0 +1,6 @@
+#ifndef EXEC_H
+#define EXEC_H
+
+int exec(const char **argv);
+
+#endif
diff --git a/lib/sys/unmount.h b/lib/sys/unmount.h
new file mode 100644
index 0000000..1331e65
--- /dev/null
+++ b/lib/sys/unmount.h
@@ -0,0 +1,11 @@
+#ifndef UNMOUNT_H
+#define UNMOUNT_H
+
+#include "syscalls.h"
+
+int unmount(char *pathname, int flags)
+{
+ return syscall(UMOUNT2, pathname, flags);
+}
+
+#endif