aboutsummaryrefslogtreecommitdiff
path: root/src/util/getopt_helpers.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-03-29 12:51:26 +0200
committerChristian Grothoff <christian@grothoff.org>2020-03-29 12:51:26 +0200
commit73514dd0e561b521c2c23eb6038301eac3cdcbb1 (patch)
tree26506453dd21572c85fbb3f81dbade064ed39781 /src/util/getopt_helpers.c
parent0eaaeeeccd18fcfdef4c37ea56fc40daf097706a (diff)
downloadgnunet-73514dd0e561b521c2c23eb6038301eac3cdcbb1.tar.gz
gnunet-73514dd0e561b521c2c23eb6038301eac3cdcbb1.zip
allow passing of fancy time to timetravel option
Diffstat (limited to 'src/util/getopt_helpers.c')
-rw-r--r--src/util/getopt_helpers.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/util/getopt_helpers.c b/src/util/getopt_helpers.c
index a2572ccab..f053158ae 100644
--- a/src/util/getopt_helpers.c
+++ b/src/util/getopt_helpers.c
@@ -623,18 +623,42 @@ set_timetravel_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
623 const char *value) 623 const char *value)
624{ 624{
625 long long delta; 625 long long delta;
626 long long minus;
627 struct GNUNET_TIME_Relative rt;
626 628
627 (void) scls; 629 (void) scls;
628 (void) ctx; 630 (void) ctx;
629 if (1 != sscanf (value, 631 while (isspace (value[0]))
630 "%lld", 632 value++;
631 &delta)) 633 minus = 1;
634 if (value[0] == '-')
635 {
636 minus = -1;
637 value++;
638 }
639 else if (value[0] == '+')
640 {
641 value++;
642 }
643 if (GNUNET_OK !=
644 GNUNET_STRINGS_fancy_time_to_relative (value,
645 &rt))
632 { 646 {
633 fprintf (stderr, 647 fprintf (stderr,
634 _ ("You must pass a number to the `%s' option.\n"), 648 _ (
649 "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
650 option);
651 return GNUNET_SYSERR;
652 }
653 if (rt.rel_value_us > LONG_LONG_MAX)
654 {
655 fprintf (stderr,
656 _ ("Value given for time travel `%s' option is too big.\n"),
635 option); 657 option);
636 return GNUNET_SYSERR; 658 return GNUNET_SYSERR;
637 } 659 }
660 delta = (long long) rt.rel_value_us;
661 delta *= minus;
638 GNUNET_TIME_set_offset (delta); 662 GNUNET_TIME_set_offset (delta);
639 return GNUNET_OK; 663 return GNUNET_OK;
640} 664}