diff options
author | Rob Landley <rob@landley.net> | 2014-07-03 20:30:52 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-07-03 20:30:52 -0500 |
commit | feb696ae85c34ba65da30fde9545153398b1a2de (patch) | |
tree | 2b424f97c198f877d2ab9a52fbf3e0299d2bbab8 /toys | |
parent | 5ce682e4f4b0c789d591afce1e053efd01313f2d (diff) | |
download | toybox-feb696ae85c34ba65da30fde9545153398b1a2de.tar.gz |
date -r wasn't saving the result in the right variable. (And make date -ur work.)
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/date.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/toys/posix/date.c b/toys/posix/date.c index 15aafb0b..d4c4524b 100644 --- a/toys/posix/date.c +++ b/toys/posix/date.c @@ -7,7 +7,7 @@ * Note: setting a 2 year date is 50 years back/forward from today, * not posix's hardwired magic dates. -USE_DATE(NEWTOY(date, "d:s:r:u", TOYFLAG_BIN)) +USE_DATE(NEWTOY(date, "d:s:r:u[!dr]", TOYFLAG_BIN)) config DATE bool "date" @@ -96,7 +96,6 @@ void date_main(void) { char *setdate = *toys.optargs, *format_string = "%a %b %e %H:%M:%S %Z %Y", *tz = 0; - time_t now = time(NULL); struct tm tm; // We can't just pass a timezone to mktime because posix. @@ -106,19 +105,25 @@ void date_main(void) tzset(); } - if (TT.file) { - struct stat st; - - xstat(TT.file, &st); - now = st.st_mtim.tv_sec; - } else if (TT.showdate) { + if (TT.showdate) { setdate = TT.showdate; if (TT.setfmt) { char *s = strptime(TT.showdate, TT.setfmt+(*TT.setfmt=='+'), &tm); if (!s || *s) goto bad_date; } else if (parse_posixdate(TT.showdate, &tm)) goto bad_date; - } else localtime_r(&now, &tm); + } else { + time_t now; + + if (TT.file) { + struct stat st; + + xstat(TT.file, &st); + now = st.st_mtim.tv_sec; + } else now = time(0); + + ((toys.optflags & FLAG_u) ? gmtime_r : localtime_r)(&now, &tm); + } setdate = *toys.optargs; // Fall through if no arguments |