summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-10-24 19:10:09 +0200
committerLennart Poettering <lennart@poettering.net>2014-10-24 19:10:09 +0200
commitbb1fada8cc691821ade680c36dfb2be13e0658d6 (patch)
tree2bdfc334e67aff1f89456d333cc3e9f07a49b3ef /src
parent75a5f1d837739fc84a7c5af14797490774a10646 (diff)
time: don't do comparison twice
Diffstat (limited to 'src')
-rw-r--r--src/shared/time-util.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index 33d0822f33..d3404afd55 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -296,8 +296,14 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
assert(buf);
assert(l > 0);
- if (t == USEC_INFINITY || t <= 0) {
- strncpy(p, t == USEC_INFINITY ? "infinity" : "0", l);
+ if (t == USEC_INFINITY) {
+ strncpy(p, "infinity", l-1);
+ p[l-1] = 0;
+ return p;
+ }
+
+ if (t <= 0) {
+ strncpy(p, "0", l-1);
p[l-1] = 0;
return p;
}