diff options
author | P. J. McDermott <pj@pehjota.net> | 2022-03-16 21:00:05 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2022-03-17 16:17:43 (EDT) |
commit | 88c7e69ef39f66ef46a1eff5a306c1243690d7d6 (patch) | |
tree | 711c13b2f95b601fcdc5f97955b299f9bfc54cf1 | |
parent | c617d8239d104c206696aa0afc77753dad3f731d (diff) | |
download | atsign-88c7e69ef39f66ef46a1eff5a306c1243690d7d6.zip atsign-88c7e69ef39f66ef46a1eff5a306c1243690d7d6.tar.gz atsign-88c7e69ef39f66ef46a1eff5a306c1243690d7d6.tar.bz2 |
main: Add undocumented debugging option
Prints the number of seconds between the UNIX epoch and the specified
time.
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/main.c | 31 |
2 files changed, 29 insertions, 4 deletions
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]) @@ -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) { |