networkd: fix and simplify format_lifetime()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Jul 2021 17:40:41 +0000 (19:40 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 19 Jul 2021 17:43:57 +0000 (19:43 +0200)
commita35f3128e606082c35504a367109105ad463157f
tree024d7c858832f2c79e27b861b22a40310accca80
parent95b63c755b73606e3dce094d92024c1e57ee5ed4
networkd: fix and simplify format_lifetime()

We would copy "forever" into the buffer. This is a fairly common case, so let's
do a microoptimization and return a static string. (All callers use the return
pointer, so this works just as well.)

The prefix "for " was not displayed, because the pointer to the part of the
buffer after "for " was returned. (Maybe it's just me, but I find strpcpy()
and associated functions really hard to use… I always have to look up what the
do exactly and what the return value is.)

A simple test is added.
src/network/meson.build
src/network/networkd-address.c
src/network/networkd-address.h
src/network/test-networkd-address.c [new file with mode: 0644]