diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-09-28 21:19:07 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-09-29 03:37:06 +0900 |
commit | 01afd0f7f53f7807294ce7c008ecf8a043a920fe (patch) | |
tree | 3aa92ca8449a2a4222aa51e6e9a36d3ca1f7d24a /src/basic/format-util.h | |
parent | 1641c2b1123617f7be249bb7f2b2c408defb3b96 (diff) | |
download | systemd-01afd0f7f53f7807294ce7c008ecf8a043a920fe.tar.gz |
tree-wide: make format_ifname() or friends return negative errno on failure
Also,
- drop unnecessary +1 from buffer size, as IF_NAMESIZE or IFNAMSIZ
includes the nul at the end.
- format_ifname() does not update buffer on failure,
- introduces format_ifname_alloc(), FORMAT_IFNAME(), and their friends.
Diffstat (limited to 'src/basic/format-util.h')
-rw-r--r-- | src/basic/format-util.h | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/basic/format-util.h b/src/basic/format-util.h index 579f231897..7dd422b987 100644 --- a/src/basic/format-util.h +++ b/src/basic/format-util.h @@ -61,11 +61,24 @@ typedef enum { FORMAT_IFNAME_IFINDEX_WITH_PERCENT = (1 << 1) | FORMAT_IFNAME_IFINDEX, } FormatIfnameFlag; -char *format_ifname_full(int ifindex, char buf[static IF_NAMESIZE + 1], FormatIfnameFlag flag); -static inline char *format_ifname(int ifindex, char buf[static IF_NAMESIZE + 1]) { - return format_ifname_full(ifindex, buf, 0); +int format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]); +int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret); + +static inline int format_ifname(int ifindex, char buf[static IF_NAMESIZE]) { + return format_ifname_full(ifindex, 0, buf); +} +static inline int format_ifname_alloc(int ifindex, char **ret) { + return format_ifname_full_alloc(ifindex, 0, ret); } +static inline char *_format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NAMESIZE]) { + (void) format_ifname_full(ifindex, flag, buf); + return buf; +} + +#define FORMAT_IFNAME_FULL(index, flag) _format_ifname_full(index, flag, (char[IF_NAMESIZE]){}) +#define FORMAT_IFNAME(index) _format_ifname_full(index, 0, (char[IF_NAMESIZE]){}) + typedef enum { FORMAT_BYTES_USE_IEC = 1 << 0, FORMAT_BYTES_BELOW_POINT = 1 << 1, |