summaryrefslogtreecommitdiff
path: root/src/util
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
parent0eaaeeeccd18fcfdef4c37ea56fc40daf097706a (diff)
allow passing of fancy time to timetravel option
Diffstat (limited to 'src/util')
-rw-r--r--src/util/common_logging.c4
-rw-r--r--src/util/getopt_helpers.c32
2 files changed, 31 insertions, 5 deletions
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 27ac88a05..527dffc02 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -705,7 +705,9 @@ parse_all_definitions ()
* @return #GNUNET_OK on success
*/
int
-GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
+GNUNET_log_setup (const char *comp,
+ const char *loglevel,
+ const char *logfile)
{
const char *env_logfile;
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,
const char *value)
{
long long delta;
+ long long minus;
+ struct GNUNET_TIME_Relative rt;
(void) scls;
(void) ctx;
- if (1 != sscanf (value,
- "%lld",
- &delta))
+ while (isspace (value[0]))
+ value++;
+ minus = 1;
+ if (value[0] == '-')
+ {
+ minus = -1;
+ value++;
+ }
+ else if (value[0] == '+')
+ {
+ value++;
+ }
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_fancy_time_to_relative (value,
+ &rt))
{
fprintf (stderr,
- _ ("You must pass a number to the `%s' option.\n"),
+ _ (
+ "You must pass a relative time (optionally with sign) to the `%s' option.\n"),
+ option);
+ return GNUNET_SYSERR;
+ }
+ if (rt.rel_value_us > LONG_LONG_MAX)
+ {
+ fprintf (stderr,
+ _ ("Value given for time travel `%s' option is too big.\n"),
option);
return GNUNET_SYSERR;
}
+ delta = (long long) rt.rel_value_us;
+ delta *= minus;
GNUNET_TIME_set_offset (delta);
return GNUNET_OK;
}