aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/touch.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-12-04 21:29:51 -0600
committerRob Landley <rob@landley.net>2018-12-04 21:29:51 -0600
commit747e296ff656813340c9355d98b0a13cba8473bc (patch)
treee7ef2b20be56e2e5a2062168aa822fd6c6139b7d /toys/posix/touch.c
parent141a075c0e192dc9910e777270114b1864270bfd (diff)
downloadtoybox-747e296ff656813340c9355d98b0a13cba8473bc.tar.gz
Add FLAG(x) macro, expanding to (toys.optflags & FLAG_##x)
Diffstat (limited to 'toys/posix/touch.c')
-rw-r--r--toys/posix/touch.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/toys/posix/touch.c b/toys/posix/touch.c
index 17a0a3ed..3775c8bc 100644
--- a/toys/posix/touch.c
+++ b/toys/posix/touch.c
@@ -41,7 +41,7 @@ void touch_main(void)
// use current time if no -t or -d
ts[0].tv_nsec = UTIME_NOW;
- if (toys.optflags & (FLAG_t|FLAG_d)) {
+ if (FLAG(t) || FLAG(d)) {
char *s, *date, **format;
struct tm tm;
int len = 0;
@@ -51,7 +51,7 @@ void touch_main(void)
ts->tv_nsec = 0;
// List of search types
- if (toys.optflags & FLAG_d) {
+ if (FLAG(d)) {
format = (char *[]){"%Y-%m-%dT%T", "%Y-%m-%d %T", 0};
date = TT.d;
} else {
@@ -67,7 +67,7 @@ void touch_main(void)
}
while (*format) {
- if (toys.optflags&FLAG_t) {
+ if (FLAG(t)) {
s = strchr(date, '.');
if ((s ? s-date : strlen(date)) != strlen(*format)) {
format++;
@@ -83,7 +83,7 @@ void touch_main(void)
// parse nanoseconds
if (s && *s=='.' && isdigit(s[1])) {
s++;
- if (toys.optflags&FLAG_t)
+ if (FLAG(t))
if (1 == sscanf(s, "%2u%n", &(tm.tm_sec), &len)) s += len;
if (1 == sscanf(s, "%lu%n", &ts->tv_nsec, &len)) {
s += len;
@@ -122,9 +122,8 @@ void touch_main(void)
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 (!utimensat(AT_FDCWD, s, ts, FLAG(h)*AT_SYMLINK_NOFOLLOW)) continue;
+ if (FLAG(c)) continue;
if (access(s, F_OK) && (-1!=(fd = open(s, O_CREAT, 0666)))) {
close(fd);
if (toys.optflags) ss--;