1.\" $NetBSD: devname.3,v 1.17 2017/09/10 10:12:43 wiz Exp $ 2.\" 3.\" Copyright (c) 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)devname.3 8.2 (Berkeley) 4/29/95 31.\" 32.Dd September 9, 2017 33.Dt DEVNAME 3 34.Os 35.Sh NAME 36.Nm devname , 37.Nm devname_r 38.Nd get device name 39.Sh LIBRARY 40.Lb libc 41.Sh SYNOPSIS 42.In stdlib.h 43.In sys/stat.h 44.Ft char * 45.Fn devname "dev_t dev" "mode_t type" 46.Ft int 47.Fn devname_r "dev_t dev" "mode_t type" "char *path" "size_t len" 48.Sh DESCRIPTION 49The 50.Fn devname 51function returns a pointer to the static buffer with the name of the 52block or character device in 53.Dq Pa /dev 54with a device number of 55.Fa dev , 56and a file type matching the one encoded in 57.Fa type 58which must be one of S_IFBLK or S_IFCHR. 59If no device matches the specified values, or no information is 60available, 61.Dv NULL 62is returned. 63.Pp 64The 65.Fn devname_r 66function is a reentrant and thread-safe version of 67.Fn devname . 68This function returns the device name by copying it into the 69.Fa path 70argument with up to 71.Fa len 72characters. 73The 74.Fa path 75argument is always nul-terminated. 76.Pp 77The traditional display for applications when no device is 78found is the string 79.Dq ?? . 80.Sh RETURN VALUES 81If successful, 82.Fn devname 83returns a pointer to a nul-terminated string containing the name of the device. 84If an error occurs 85.Fa devname 86will return 87.Dv NULL . 88.Pp 89If successful, 90.Fn devname_r 91places a nul-terminated string containing the name of the device in 92the buffer pointed to by 93.Ar path 94and returns 0. 95If an error occurs 96.Fn devname_r 97will return an error number from 98.In sys/errno.h 99indicating what went wrong. 100.Sh FILES 101.Bl -tag -width /var/run/dev.cdb -compact 102.It Pa /var/run/dev.cdb 103Device database file. 104.El 105.Sh ERRORS 106The 107.Fn devname_r 108function may fail if: 109.Bl -tag -width Er 110.It Bq Er ENOENT 111The corresponding device does not exist. 112.It Bq Er ERANGE 113The passed buffer length is too short. 114.El 115.Sh SEE ALSO 116.Xr stat 2 , 117.Xr dev_mkdb 8 118.Sh HISTORY 119The 120.Nm devname 121function call appeared in 122.Bx 4.4 . 123.Pp 124The 125.Fn devname_r 126function first appeared in 127.Nx 6.0 . 128