diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 31 |
1 files changed, 28 insertions, 3 deletions
@@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 P. J. McDermott + * Copyright (C) 2021, 2022 P. J. McDermott * * This file is part of @ * @@ -18,6 +18,7 @@ */ #include <errno.h> +#include <inttypes.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -56,6 +57,18 @@ static const struct option LONGOPTS_[] = { }; #endif +static struct tm EPOCH_ = { + .tm_sec = 0, + .tm_min = 0, + .tm_hour = 0, + .tm_mday = 1, + .tm_mon = 0, + .tm_year = 70, + .tm_wday = 4, + .tm_yday = 0, + .tm_isdst = -1, +}; + static void _print_usage(FILE *stream, const char *program_name) { @@ -168,18 +181,20 @@ _concat_args(int argc, char * const argv[]) int main(int argc, char * const argv[]) { + bool dbg; int opt; char *buf; time_t arg; time_t now; double dif; + dbg = false; optind = 1; opterr = 0; #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG - while ((opt = getopt_long(argc, argv, "FhV", LONGOPTS_, NULL)) > 0) { + while ((opt = getopt_long(argc, argv, "FhVd", LONGOPTS_, NULL)) > 0) { #else - while ((opt = getopt(argc, argv, "FhV")) > 0) { + while ((opt = getopt(argc, argv, "FhVd")) > 0) { #endif switch (opt) { case 'F': @@ -191,6 +206,9 @@ main(int argc, char * const argv[]) case 'V': _print_version(); return EXIT_SUCCESS; + case 'd': + dbg = true; + break; default: _print_usage(stderr, argv[0]); #if defined(HAVE_GETOPT_LONG) && HAVE_GETOPT_LONG @@ -217,6 +235,13 @@ main(int argc, char * const argv[]) } free(buf); + if (dbg == true) { + now = timegm(&EPOCH_); + dif = difftime(arg, now); + printf("%" PRId64 "\n", (int64_t) dif); + return EXIT_SUCCESS; + } + time(&now); dif = difftime(arg, now); if (dif >= 1000 * 24 * 60 * 60) { |