diff options
author | Rob Landley <rob@landley.net> | 2016-10-20 16:35:13 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2016-10-20 16:35:13 -0500 |
commit | 9c0ad3248ff89dc9c9dc9eed193ce6fd378d85fa (patch) | |
tree | 03c9d5d95b775a47a62e3e0898dfef2bbbc3212a /toys/posix | |
parent | d5e0ab8715eff1c16dedb3f60fa32c480153db69 (diff) | |
download | toybox-9c0ad3248ff89dc9c9dc9eed193ce6fd378d85fa.tar.gz |
Add special "touch -" behavior and require an argument.
Diffstat (limited to 'toys/posix')
-rw-r--r-- | toys/posix/touch.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/toys/posix/touch.c b/toys/posix/touch.c index c18087a9..79eba177 100644 --- a/toys/posix/touch.c +++ b/toys/posix/touch.c @@ -4,7 +4,7 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html -USE_TOUCH(NEWTOY(touch, "acd:mr:t:h[!dtr]", TOYFLAG_BIN)) +USE_TOUCH(NEWTOY(touch, "<1acd:mr:t:h[!dtr]", TOYFLAG_BIN)) config TOUCH bool "touch" @@ -115,13 +115,21 @@ void touch_main(void) // Loop through files on command line for (ss = toys.optargs; *ss;) { + char *s = *ss++; - // cheat: FLAG_h is rightmost flag, so its value is 1 - if (!utimensat(AT_FDCWD, *ss, ts, - (toys.optflags & FLAG_h)*AT_SYMLINK_NOFOLLOW)) ss++; - else if (toys.optflags & FLAG_c) ss++; - else if (access(*ss, F_OK) && (-1!=(fd = open(*ss, O_CREAT, 0666)))) - close(fd); - else perror_msg("'%s'", *ss++); + if (!strcmp(s, "-")) { + if (!futimens(1, ts)) continue; + } else { + // cheat: FLAG_h is rightmost flag, so its value is 1 + if (!utimensat(AT_FDCWD, s, ts, + (toys.optflags & FLAG_h)*AT_SYMLINK_NOFOLLOW)) continue; + if (toys.optflags & FLAG_c) continue; + if (access(s, F_OK) && (-1!=(fd = open(s, O_CREAT, 0666)))) { + close(fd); + if (toys.optflags) ss--; + continue; + } + } + perror_msg("'%s'", s); } } |