diff options
author | Andreas Kling <awesomekling@gmail.com> | 2018-12-19 21:14:55 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2018-12-19 21:14:55 +0100 |
commit | 038d8641f9394aa587c0fa06878b6798a80dbcda (patch) | |
tree | ab29b5465d3db41e21e8470915d82fdb24f9fea3 /Userland | |
parent | e03d341615119788037f9e50c9043a30a2449894 (diff) | |
download | serenity-038d8641f9394aa587c0fa06878b6798a80dbcda.zip |
Implement utime() along with a naive /bin/touch.
This synchronous approach to inodes is silly, obviously. I need to rework
it so that the in-memory CoreInode object is the canonical inode, and then
we just need a sync() that flushes pending changes to disk.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/.gitignore | 1 | ||||
-rw-r--r-- | Userland/Makefile | 9 | ||||
-rw-r--r-- | Userland/ls.cpp | 2 | ||||
-rw-r--r-- | Userland/touch.cpp | 16 |
4 files changed, 26 insertions, 2 deletions
diff --git a/Userland/.gitignore b/Userland/.gitignore index 5bb5aee8b9..c5f95143dc 100644 --- a/Userland/.gitignore +++ b/Userland/.gitignore @@ -21,3 +21,4 @@ ft2 strsignal fgrep mkdir +touch diff --git a/Userland/Makefile b/Userland/Makefile index e8f5195036..30abcc2e79 100644 --- a/Userland/Makefile +++ b/Userland/Makefile @@ -19,7 +19,8 @@ OBJS = \ strsignal.o \ fgrep.o \ tty.o \ - mkdir.o + mkdir.o \ + touch.o APPS = \ id \ @@ -42,7 +43,8 @@ APPS = \ strsignal \ fgrep \ tty \ - mkdir + mkdir \ + touch ARCH_FLAGS = STANDARD_FLAGS = -std=c++17 -nostdinc++ -nostdlib -nostdinc @@ -125,6 +127,9 @@ strsignal: strsignal.o mkdir: mkdir.o $(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a +touch: touch.o + $(LD) -o $@ $(LDFLAGS) $< ../LibC/LibC.a + .cpp.o: @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o $@ -c $< diff --git a/Userland/ls.cpp b/Userland/ls.cpp index edcacb8971..622dc928cc 100644 --- a/Userland/ls.cpp +++ b/Userland/ls.cpp @@ -152,6 +152,8 @@ int do_dir(const char* path) printf(" %10u ", st.st_size); + printf(" %10u ", st.st_mtime); + print_name(st, de->d_name, pathbuf); printf("\n"); diff --git a/Userland/touch.cpp b/Userland/touch.cpp new file mode 100644 index 0000000000..6d857198f6 --- /dev/null +++ b/Userland/touch.cpp @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <utime.h> +#include <sys/types.h> + +int main(int argc, char** argv) +{ + if (argc != 2) { + fprintf(stderr, "usage: touch <path>\n"); + return 1; + } + int rc = utime(argv[1], nullptr); + if (rc < 0) + perror("utime"); + return 0; +} + |