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.
This commit is contained in:
Yu Watanabe
2021-09-29 03:37:06 +09:00
parent 1641c2b112
commit 01afd0f7f5
13 changed files with 99 additions and 94 deletions
+2 -9
View File
@@ -1665,16 +1665,9 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas
case TABLE_IFINDEX: {
_cleanup_free_ char *p = NULL;
char name[IF_NAMESIZE + 1];
if (format_ifname(d->ifindex, name)) {
p = strdup(name);
if (!p)
return NULL;
} else {
if (asprintf(&p, "%i" , d->ifindex) < 0)
return NULL;
}
if (format_ifname_full_alloc(d->ifindex, FORMAT_IFNAME_IFINDEX, &p) < 0)
return NULL;
d->formatted = TAKE_PTR(p);
break;