mirror of
https://github.com/systemd/systemd.git
synced 2025-02-10 17:57:40 +03:00
time-util: change parse_sec_fix_0() to accept "0s" for infinity too (#10501)
This function is about compatibility, nothing else, hence we should make it properly compatible. Fixes: #9556
This commit is contained in:
parent
d776fd08a3
commit
def34f63fe
@ -1074,18 +1074,19 @@ int parse_sec(const char *t, usec_t *usec) {
|
||||
return parse_time(t, usec, USEC_PER_SEC);
|
||||
}
|
||||
|
||||
int parse_sec_fix_0(const char *t, usec_t *usec) {
|
||||
int parse_sec_fix_0(const char *t, usec_t *ret) {
|
||||
usec_t k;
|
||||
int r;
|
||||
|
||||
assert(t);
|
||||
assert(usec);
|
||||
assert(ret);
|
||||
|
||||
t += strspn(t, WHITESPACE);
|
||||
r = parse_sec(t, &k);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (streq(t, "0")) {
|
||||
*usec = USEC_INFINITY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return parse_sec(t, usec);
|
||||
*ret = k == 0 ? USEC_INFINITY : k;
|
||||
return r;
|
||||
}
|
||||
|
||||
int parse_nsec(const char *t, nsec_t *nsec) {
|
||||
|
@ -65,7 +65,7 @@ static void test_parse_sec_fix_0(void) {
|
||||
assert_se(parse_sec_fix_0("5s", &u) >= 0);
|
||||
assert_se(u == 5 * USEC_PER_SEC);
|
||||
assert_se(parse_sec_fix_0("0s", &u) >= 0);
|
||||
assert_se(u == 0 * USEC_PER_SEC);
|
||||
assert_se(u == USEC_INFINITY);
|
||||
assert_se(parse_sec_fix_0("0", &u) >= 0);
|
||||
assert_se(u == USEC_INFINITY);
|
||||
assert_se(parse_sec_fix_0(" 0", &u) >= 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user