]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
time-util: accept "µs" as time unit, in addition to "us" (#4836)
authorLennart Poettering <lennart@poettering.net>
Tue, 6 Dec 2016 09:51:26 +0000 (10:51 +0100)
committerMartin Pitt <martin.pitt@ubuntu.com>
Tue, 6 Dec 2016 09:51:26 +0000 (10:51 +0100)
Let's accept "µs" as alternative time unit for microseconds. We already accept
"us" and "usec" for them, lets extend on this and accept the proper scientific
unit specification too.

We will never output this as time unit, but it's fine to accept it, after all
we are pretty permissive with time units already.

src/basic/time-util.c
src/test/test-time.c

index cbdfd55ada7acbfe1719d908cc75bc9fdedb6179..7a5b29d77e5cfa5dfeb501fc0dc2c7b65cd91ced 100644 (file)
@@ -883,6 +883,7 @@ static char* extract_multiplier(char *p, usec_t *multiplier) {
                 { "y",       USEC_PER_YEAR   },
                 { "usec",    1ULL            },
                 { "us",      1ULL            },
+                { "µs",      1ULL            },
         };
         unsigned i;
 
@@ -1016,6 +1017,7 @@ int parse_nsec(const char *t, nsec_t *nsec) {
                 { "y", NSEC_PER_YEAR },
                 { "usec", NSEC_PER_USEC },
                 { "us", NSEC_PER_USEC },
+                { "µs", NSEC_PER_USEC },
                 { "nsec", 1ULL },
                 { "ns", 1ULL },
                 { "", 1ULL }, /* default is nsec */
index 7078a0374d292a76ce002e89fe462ccb0129fe81..8259491813415accd9c7523d33e929ed339192dd 100644 (file)
@@ -42,6 +42,10 @@ static void test_parse_sec(void) {
         assert_se(u == 2500 * USEC_PER_MSEC);
         assert_se(parse_sec(".7", &u) >= 0);
         assert_se(u == 700 * USEC_PER_MSEC);
+        assert_se(parse_sec("23us", &u) >= 0);
+        assert_se(u == 23);
+        assert_se(parse_sec("23µs", &u) >= 0);
+        assert_se(u == 23);
         assert_se(parse_sec("infinity", &u) >= 0);
         assert_se(u == USEC_INFINITY);
         assert_se(parse_sec(" infinity ", &u) >= 0);