diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-04-04 17:06:00 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-04-04 17:06:00 +0200 |
commit | 7c537b2e2826139bb73c6eee15d46bf9f7e6059f (patch) | |
tree | 5014dd95a48bac6260af992b885220a4f008d8ce /src/shared/time-util.c | |
parent | 5c0d398dfc4d79df2209515d28cafd9dc129838e (diff) |
util: tweak format_timespan() a bit
Make sure to always print out at least one valid component instead of
falling back early to 0.
Diffstat (limited to 'src/shared/time-util.c')
-rw-r--r-- | src/shared/time-util.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c index b6a2bec156..9ee711a49e 100644 --- a/src/shared/time-util.c +++ b/src/shared/time-util.c @@ -251,6 +251,12 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { if (t == (usec_t) -1) return NULL; + if (t <= 0) { + snprintf(p, l, "0"); + p[l-1] = 0; + return p; + } + /* The result of this function can be parsed with parse_sec */ for (i = 0; i < ELEMENTSOF(table); i++) { @@ -259,15 +265,11 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { bool done = false; usec_t a, b; - if (t == 0 || t < accuracy) { - if (!something) { - snprintf(p, l, "0"); - p[l-1] = 0; - return p; - } + if (t <= 0) + break; + if (t < accuracy && something) break; - } if (t < table[i].usec) continue; @@ -322,7 +324,6 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { l -= n; p += n; - something = true; } |