#include <stdlib.h> char *
devname (dev_t dev mode_t type); char *
devname_r (dev_t dev mode_t type char *buf int len);
function returns a pointer to the name of the block or character
with a device number of
Fa dev ,
and a file type matching the one encoded in
which must be one of
To find the right name,
asks the kernel via the
If it is unable to come up with a suitable name,
it will format the information encapsulated in
in a human-readable format.
returns the name stored in a static buffer which will be overwritten
on subsequent calls.
takes a buffer and length as argument to avoid this problem.
struct stat buf;
fd = open("/dev/tun");
printf("devname is /dev/%s\n", devname(buf.st_rdev, S_IFCHR));