util: introduce format_ifname()

This commit is contained in:
Yu Watanabe 2019-05-29 14:03:18 +09:00
parent 658e910640
commit 7f686722f7
3 changed files with 14 additions and 0 deletions

10
src/basic/format-util.c Normal file
View File

@ -0,0 +1,10 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "format-util.h"
#include "memory-util.h"
char *format_ifname(int ifindex, char buf[static IF_NAMESIZE + 1]) {
/* Buffer is always cleared */
memzero(buf, IF_NAMESIZE + 1);
return if_indextoname(ifindex, buf);
}

View File

@ -2,6 +2,7 @@
#pragma once
#include <inttypes.h>
#include <net/if.h>
#if SIZEOF_PID_T == 4
# define PID_PRI PRIi32
@ -65,3 +66,5 @@
#else
# error Unknown ino_t size
#endif
char *format_ifname(int ifindex, char buf[static IF_NAMESIZE + 1]);

View File

@ -56,6 +56,7 @@ basic_sources = files('''
fd-util.h
fileio.c
fileio.h
format-util.c
format-util.h
fs-util.c
fs-util.h