From 3886749b1c8d79d4701bf6b8e66249c4e1491648 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sun, 4 Jan 2026 18:06:31 +0800 Subject: dev(shell): implement basic shell tools fixed(file-system): fixed read and write bugs --- src/user/touch.cc | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/user/touch.cc (limited to 'src/user/touch.cc') diff --git a/src/user/touch.cc b/src/user/touch.cc new file mode 100644 index 0000000..b978f52 --- /dev/null +++ b/src/user/touch.cc @@ -0,0 +1,27 @@ +#include "ulib/stdio.h" +#include "ulib/stdlib.h" +#include "user/user.h" +#include "common/fcntl.h" + +int main(int argc, char *argv[]) +{ + int i, fd; + + if (argc < 2) + { + printf("Usage: touch files...\n"); + exit(1); + } + + for (i = 1; i < argc; i++) + { + fd = open(argv[i], O_CREATE | O_RDWR); + if (fd < 0) + { + printf("touch: cannot touch %s\n", argv[i]); + exit(1); + } + close(fd); + } + exit(0); +} \ No newline at end of file -- cgit v1.2.3