coreutils

custom mini coreutils
git clone git://git.evenfri.duckdns.org/coreutils.git
Log | Files | Refs | README

commit 3769747bdd8693a69b921b7f72d4813756c7f568
parent 4d7e03339ee37e06a140d3cc32b170910d8eef72
Author: evenfri <evenfri256@gmail.com>
Date:   Mon, 10 Aug 2026 04:00:29 +0800

update gitignore, add touch

Diffstat:
M.gitignore | 1+
Mmkfile | 15++++++++-------
Atouch.c | 25+++++++++++++++++++++++++
3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -2,3 +2,4 @@ **/o.* mk-standalone/ libc/ +test/ diff --git a/mkfile b/mkfile @@ -6,13 +6,14 @@ ld = ld cflags = -I./libc lib = ./libc/libc.a -targ = init \ - echo \ - cat \ - pwd \ - ls \ - free \ - sh \ +targ = init \ + echo \ + cat \ + pwd \ + ls \ + free \ + sh \ + touch \ <$PLAN9/src/mkmany diff --git a/touch.c b/touch.c @@ -0,0 +1,25 @@ +#include <libc.h> + +#define eexist 17 + +int main(int argc, char *argv[]) { + if (argc < 2) { + return 1; + } + + for (int i = 1; i < argc; i++) { + char *p = argv[i]; + int fd = open(p, o_creat | o_excl | o_wronly, 0666); + if (fd == -1) { + if (errno == eexist) { + if (utime(p, NULL) == -1) { + write(stderr, "touch: utime: error\n", 20); + } + } + } else { + close(fd); + } + } + + return 0; +}