aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-10-19 20:51:28 -0500
committerRob Landley <rob@landley.net>2016-10-19 20:51:28 -0500
commit354ff6831412eb88c64e9f497a382d926dc7b9bd (patch)
treeafd03ab495e50e08bb0ea06b7ea7d41b8b2cee34 /toys
parentee14fc396dff50a263b62670f5484efcd6316aeb (diff)
downloadtoybox-354ff6831412eb88c64e9f497a382d926dc7b9bd.tar.gz
More touch tests, and a fix found by one. (The three -t formats can only
reliably be distinguished by checking length, because %H amd %m and such can match different numbers of digits.)
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/touch.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/toys/posix/touch.c b/toys/posix/touch.c
index 79928cee..c18087a9 100644
--- a/toys/posix/touch.c
+++ b/toys/posix/touch.c
@@ -54,7 +54,7 @@ void touch_main(void)
format = (char *[]){"%Y-%m-%dT%T", "%Y-%m-%d %T", 0};
date = TT.date;
} else {
- format = (char *[]){"%Y%m%d%H%M", "%m%d%H%M", "%y%m%d%H%M", 0};
+ format = (char *[]){"%m%d%H%M", "%y%m%d%H%M", "%C%y%m%d%H%M", 0};
date = TT.time;
}
@@ -66,6 +66,13 @@ void touch_main(void)
}
while (*format) {
+ if (toys.optflags&FLAG_t) {
+ s = strchr(date, '.');
+ if ((s ? s-date : strlen(date)) != strlen(*format)) {
+ format++;
+ continue;
+ }
+ }
localtime_r(&(ts->tv_sec), &tm);
// Adjusting for daylight savings time gives the wrong answer.
tm.tm_isdst = 0;