aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/new.c45
1 files changed, 45 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;
+}