sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit 444de72fd32218764b8e053f0dc32b6af423524c
parent 8ec404cdec24bc9af7ebb63f5ac4835e7bf7d623
Author: Connor Lane Smith <cls@lubutu.com>
Date:   Sat Jun 18 06:43:10 +0100

touch: posix open
Diffstat:
kill.1 | 3++-
touch.c | 27+++++++++++++++------------
2 files changed, 17 insertions(+), 13 deletions(-)
diff --git a/kill.1 b/kill.1 @@ -25,4 +25,5 @@ lists available signals. If a .I signum is given, only the corresponding signal name will be printed. .SH SEE ALSO -.IR kill (2) +.IR kill (2), +.IR signal (7) diff --git a/touch.c b/touch.c @@ -43,17 +43,20 @@ touch(const char *str) struct stat st; struct utimbuf ut; - if(stat(str, &st) == -1) { - if(errno != ENOENT) - eprintf("stat %s:", str); - if(cflag) - return; - if((fd = creat(str, O_EXCL|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) < 0) - eprintf("creat %s:", str); - close(fd); + if(stat(str, &st) == 0) { + ut.actime = st.st_atime; + ut.modtime = t; + if(utime(str, &ut) == -1) + eprintf("utime %s:", str); + return; } - ut.actime = st.st_atime; - ut.modtime = t; - if(utime(str, &ut) == -1) - eprintf("utime %s:", str); + else if(errno != ENOENT) + eprintf("stat %s:", str); + else if(cflag) + return; + if((fd = open(str, O_CREAT|O_EXCL, + S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) == -1) + eprintf("open %s:", str); + close(fd); + touch(str); }