aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/new.c45
-rw-r--r--lib/sys/creat.h11
-rw-r--r--lib/sys/mkdir.h11
3 files changed, 67 insertions, 0 deletions
diff --git a/core/new.c b/core/new.c
new file mode 100644
index 0000000..5c0e7b8
--- /dev/null
+++ b/core/new.c
@@ -0,0 +1,45 @@
+#include "../lib/io/io.h"
+#include "../lib/sys/mkdir.h"
+#include "../lib/sys/creat.h"
+#include "../lib/cstr/cstr.h"
+
+enum {
+ FILE,
+ DIRECTORY,
+ NUMBER_OF_MODES,
+};
+
+void new_file(char *path);
+void new_directory(char *path);
+
+int(*new_funcs[NUMBER_OF_MODES])(const char *, unsigned int) = {
+ &creat,
+ &mkdir
+};
+
+int main(int argc, char **argv)
+{
+ if (argc < 3) {
+ wff(STDERR_FD, "new [-f | -d] <name> ...");
+ return -1;
+ }
+
+ int type = FILE;
+
+ if (cstr_length(argv[1]) != 2) {
+ wff(STDERR_FD, "error: unknown entry type.\n");
+ return -1;
+ }
+
+ switch(argv[1][1]) {
+ case 'f': type = FILE; break;
+ case 'd': type = DIRECTORY; break;
+ default: wff(STDERR_FD, "error: unknown entry type.\n"); return -1;
+ }
+
+ for (int i = 2; i < argc; ++i) {
+ new_funcs[type](argv[i], MODE_USER_READ | MODE_USER_WRITE);
+ }
+
+ return 0;
+}
diff --git a/lib/sys/creat.h b/lib/sys/creat.h
new file mode 100644
index 0000000..9c6e492
--- /dev/null
+++ b/lib/sys/creat.h
@@ -0,0 +1,11 @@
+#ifndef CREAT_H
+#define CREAT_H
+
+#include "syscalls.h"
+
+int creat(const char *pathname, unsigned int mode)
+{
+ return syscall(CREAT, pathname, mode);
+}
+
+#endif
diff --git a/lib/sys/mkdir.h b/lib/sys/mkdir.h
new file mode 100644
index 0000000..2de3b01
--- /dev/null
+++ b/lib/sys/mkdir.h
@@ -0,0 +1,11 @@
+#ifndef MKDIR_H
+#define MKDIR_H
+
+#include "syscalls.h"
+
+int mkdir(const char *pathname, unsigned int mode)
+{
+ return syscall(MKDIR, pathname, mode);
+}
+
+#endif