chiark / gitweb /
time: also support 'infinity' syntax in parse_nsec()
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Oct 2014 17:07:26 +0000 (19:07 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 24 Oct 2014 17:07:31 +0000 (19:07 +0200)
Let's make parse_usec() and parse_nsec() work similar

src/shared/time-util.c

index 433c262..4d34362 100644 (file)
@@ -773,7 +773,7 @@ int parse_nsec(const char *t, nsec_t *nsec) {
                 { "", 1ULL }, /* default is nsec */
         };
 
-        const char *p;
+        const char *p, *s;
         nsec_t r = 0;
         bool something = false;
 
@@ -781,6 +781,18 @@ int parse_nsec(const char *t, nsec_t *nsec) {
         assert(nsec);
 
         p = t;
+
+        p += strspn(p, WHITESPACE);
+        s = startswith(p, "infinity");
+        if (s) {
+                s += strspn(s, WHITESPACE);
+                if (!*s != 0)
+                        return -EINVAL;
+
+                *nsec = NSEC_INFINITY;
+                return 0;
+        }
+
         for (;;) {
                 long long l, z = 0;
                 char *e;