diff options
author | Filipe Brandenburger <filbranden@google.com> | 2019-01-24 04:48:54 +0100 |
---|---|---|
committer | Filipe Brandenburger <filbranden@google.com> | 2019-02-14 20:04:42 +0100 |
commit | 7b61ce3c44ef5908e817009ce4f9d2a7a37722be (patch) | |
tree | c0e8cdc688bd5904c5743b25364ef2514ad763ae /src/basic/time-util.c | |
parent | Revert "README: remove Coverity Scan badge" (diff) | |
download | systemd-7b61ce3c44ef5908e817009ce4f9d2a7a37722be.tar.xz systemd-7b61ce3c44ef5908e817009ce4f9d2a7a37722be.zip |
time-util: Introduce parse_sec_def_infinity
This works like parse_sec() but defaults to USEC_INFINITY when passed an
empty string or only whitespace.
Also introduce config_parse_sec_def_infinity, which can be used to parse
config options using this function.
This is useful for time options that use "infinity" for default and that
can be reset by unsetting them.
Introduce a test case to ensure it works as expected.
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r-- | src/basic/time-util.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 62cdc305f9..25a5c116e8 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1031,6 +1031,15 @@ int parse_sec_fix_0(const char *t, usec_t *ret) { return r; } +int parse_sec_def_infinity(const char *t, usec_t *ret) { + t += strspn(t, WHITESPACE); + if (isempty(t)) { + *ret = USEC_INFINITY; + return 0; + } + return parse_sec(t, ret); +} + static const char* extract_nsec_multiplier(const char *p, nsec_t *multiplier) { static const struct { const char *suffix; |