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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user