feat: add touch command

This commit is contained in:
2026-03-25 07:49:51 +01:00
parent eb0763b078
commit 9c9a0a9712
2 changed files with 32 additions and 0 deletions
+1
View File
@@ -25,6 +25,7 @@ extern "C" void _start() {
} }
} else { } else {
montauk::print("usage: rm [file]\n"); montauk::print("usage: rm [file]\n");
montauk::exit(-1);
} }
montauk::exit(0); montauk::exit(0);
+31
View File
@@ -0,0 +1,31 @@
/*
* main.cpp
* touch command (file create)
* Copyright (c) 2026 Daniel Hammer
*/
#include <montauk/syscall.h>
#include <montauk/string.h>
extern "C" void _start() {
char args[256];
montauk::getargs((char *)&args, 256);
if (*args) {
const char* arg = montauk::skip_spaces((const char *)&args);
int fd = montauk::open(arg);
montauk::close(fd);
if (fd >= 0) { /* file already exists */
montauk::exit(0);
} else {
int fd = montauk::fcreate(arg);
montauk::close(fd);
montauk::exit(0);
}
} else {
montauk::print("usage: touch [filename]\n");
montauk::exit(-1);
}
}