From 88c7e69ef39f66ef46a1eff5a306c1243690d7d6 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 16 Mar 2022 21:00:05 -0400 Subject: main: Add undocumented debugging option Prints the number of seconds between the UNIX epoch and the specified time. --- diff --git a/configure.ac b/configure.ac index 7c94fbd..011b7d5 100644 --- a/configure.ac +++ b/configure.ac @@ -40,7 +40,7 @@ AC_CHECK_FUNCS( [\ calloc difftime fprintf fputs free isspace localtime mktime \ printf realloc setvbuf sleep strerror strlen strftime strptime \ - time + time timegm ], [], [funcs_missing=true]) diff --git a/src/main.c b/src/main.c index bb4abb5..8740753 100644 --- a/src/main.c +++ b/src/main.c @@ -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 +#include #include #include #include @@ -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) { -- cgit v0.9.1