DEVNAME(3) | Library Functions Manual | DEVNAME(3)

# NAME

`devname`, `devname_r` —
get device name

# LIBRARY

Standard C Library (libc, -lc)

# SYNOPSIS

`#include <stdlib.h>`
`#include <sys/stat.h>`

char *
`devname`(dev_t dev, mode_t type);

int
`devname_r`(dev_t dev, mode_t type, char *path, size_t len);

# DESCRIPTION

The `devname`() function returns a pointer to the static buffer with the name of the block or character device in “/dev” with a device number of dev, and a file type matching the one encoded in type which must be one of S_IFBLK or S_IFCHR. If no device matches the specified values, or no information is available, `NULL` is returned.

The `devname_r`() function is a reentrant and thread-safe version of `devname`(). This function returns the device name by copying it into the path argument with up to len characters. The path argument is always nul-terminated.

The traditional display for applications when no device is found is the string “??”.

# RETURN VALUES

If successful, `devname`() returns a pointer to a nul-terminated string containing the name of the device. If an error occurs devname will return `NULL`.

If successful, `devname_r`() places a nul-terminated string containing the name of the device in the buffer pointed to by path and returns 0. If an error occurs `devname_r`() will return an error number from `<sys/errno.h>` indicating what went wrong.

# FILES

/var/run/dev.cdb
  Device database file.

# ERRORS

The `devname_r`() function may fail if:

[`ENOENT`]
  The corresponding device does not exist.
[`ERANGE`]
  The passed buffer length is too short.

# SEE ALSO

stat(2), dev_mkdb(8)

# HISTORY

The `devname` function call appeared in 4.4BSD.

The `devname_r`() function first appeared in NetBSD 6.0.

September 9, 2017 | NetBSD 9.2