summaryrefslogtreecommitdiff
path: root/src/shared/time-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-10-24 19:10:09 +0200
committerAnthony G. Basile <blueness@gentoo.org>2014-10-25 14:12:42 -0400
commit53f0b01f222756c6e32966a9ede3d30b2cfd2d1a (patch)
treece1481471619a4e639d26e0b6f646f6a13ca2f22 /src/shared/time-util.c
parentd9c4f21a139e999f25a68ec9742350efe6d1ad06 (diff)
time: don't do comparison twice
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/time-util.c')
-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 4e12ea3ca6..3f72fdd5b2 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -99,8 +99,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;
}