diff options
author | Sami Kerola | 2013-08-29 17:11:41 +0200 |
---|---|---|
committer | Sami Kerola | 2013-08-29 19:14:08 +0200 |
commit | 75ab9bf1eb5637e5548f7c570f2086199223a436 (patch) | |
tree | e29c17a324639971dae94e46f71bbc3bbe7fe9e3 /login-utils/last.c | |
parent | last: parse easy to use time formats (diff) | |
download | kernel-qcow2-util-linux-75ab9bf1eb5637e5548f7c570f2086199223a436.tar.gz kernel-qcow2-util-linux-75ab9bf1eb5637e5548f7c570f2086199223a436.tar.xz kernel-qcow2-util-linux-75ab9bf1eb5637e5548f7c570f2086199223a436.zip |
lib/time-util: move YYYYMMDDHHMMSS to common parser
Even while the YYYYMMDDHHMMSS time format it not magnificent it is best
to make it to be part of the one, and only, time format parser.
Proposed-by: Karel Zak <kzak@redhat.com>
References: http://markmail.org/message/6baqt4ttkopu7ra6
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'login-utils/last.c')
-rw-r--r-- | login-utils/last.c | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/login-utils/last.c b/login-utils/last.c index df784361d..410e61210 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -440,45 +440,6 @@ static void __attribute__((__noreturn__)) usage(FILE *out) } -static time_t parsetm(char *ts) -{ - struct tm u, origu; - time_t tm; - - memset(&tm, 0, sizeof(tm)); - - if (sscanf(ts, "%4d%2d%2d%2d%2d%2d", &u.tm_year, - &u.tm_mon, &u.tm_mday, &u.tm_hour, &u.tm_min, - &u.tm_sec) != 6) - return (time_t)-1; - - u.tm_year -= 1900; - u.tm_mon -= 1; - u.tm_isdst = -1; - - origu = u; - - if ((tm = mktime(&u)) == (time_t)-1) - return tm; - - /* - * Unfortunately mktime() is much more forgiving than - * it should be. For example, it'll gladly accept - * "30" as a valid month number. This behavior is by - * design, but we don't like it, so we want to detect - * it and complain. - */ - if (u.tm_year != origu.tm_year || - u.tm_mon != origu.tm_mon || - u.tm_mday != origu.tm_mday || - u.tm_hour != origu.tm_hour || - u.tm_min != origu.tm_min || - u.tm_sec != origu.tm_sec) - return (time_t)-1; - - return tm; -} - static void process_wtmp_file(char *ufile, int lastb, int extended, time_t until, time_t present) { @@ -796,17 +757,11 @@ int main(int argc, char **argv) fulltime++; break; case 'p': - present = parsetm(optarg); - if (present != (time_t) -1) - break; if (parse_timestamp(optarg, &p) < 0) errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg); present = (time_t) (p / 1000000); break; case 't': - until = parsetm(optarg); - if (until != (time_t) -1) - break; if (parse_timestamp(optarg, &p) < 0) errx(EXIT_FAILURE, _("invalid time value \"%s\""), optarg); until = (time_t) (p / 1000000); |