xref: /freebsd/lib/libc/gen/fdevname.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
1 26d4f5e9SEd Schouten /*-
2 *4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3 d915a14eSPedro F. Giffuni  *
4 26d4f5e9SEd Schouten  * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
5 26d4f5e9SEd Schouten  * All rights reserved.
6 26d4f5e9SEd Schouten  *
7 26d4f5e9SEd Schouten  * Redistribution and use in source and binary forms, with or without
8 26d4f5e9SEd Schouten  * modification, are permitted provided that the following conditions
9 26d4f5e9SEd Schouten  * are met:
10 26d4f5e9SEd Schouten  * 1. Redistributions of source code must retain the above copyright
11 26d4f5e9SEd Schouten  *    notice, this list of conditions and the following disclaimer.
12 26d4f5e9SEd Schouten  * 2. Redistributions in binary form must reproduce the above copyright
13 26d4f5e9SEd Schouten  *    notice, this list of conditions and the following disclaimer in the
14 26d4f5e9SEd Schouten  *    documentation and/or other materials provided with the distribution.
15 26d4f5e9SEd Schouten  *
16 26d4f5e9SEd Schouten  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 26d4f5e9SEd Schouten  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 26d4f5e9SEd Schouten  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 26d4f5e9SEd Schouten  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 26d4f5e9SEd Schouten  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 26d4f5e9SEd Schouten  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 26d4f5e9SEd Schouten  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 26d4f5e9SEd Schouten  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 26d4f5e9SEd Schouten  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 26d4f5e9SEd Schouten  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 26d4f5e9SEd Schouten  * SUCH DAMAGE.
27 26d4f5e9SEd Schouten  */
28 26d4f5e9SEd Schouten 
29 26d4f5e9SEd Schouten #include "namespace.h"
30 26d4f5e9SEd Schouten #include <sys/param.h>
31 26d4f5e9SEd Schouten #include <sys/ioctl.h>
32 86b6b655SEd Schouten #include <stdlib.h>
33 26d4f5e9SEd Schouten #include "un-namespace.h"
34 26d4f5e9SEd Schouten 
35 26d4f5e9SEd Schouten char *
fdevname_r(int fd,char * buf,int len)36 26d4f5e9SEd Schouten fdevname_r(int fd, char *buf, int len)
37 26d4f5e9SEd Schouten {
38 26d4f5e9SEd Schouten 	struct fiodgname_arg fgn;
39 26d4f5e9SEd Schouten 
40 26d4f5e9SEd Schouten 	fgn.buf = buf;
41 26d4f5e9SEd Schouten 	fgn.len = len;
42 26d4f5e9SEd Schouten 
43 26d4f5e9SEd Schouten 	if (_ioctl(fd, FIODGNAME, &fgn) == -1)
44 26d4f5e9SEd Schouten 		return (NULL);
45 26d4f5e9SEd Schouten 	return (buf);
46 26d4f5e9SEd Schouten }
47 26d4f5e9SEd Schouten 
48 26d4f5e9SEd Schouten char *
fdevname(int fd)49 26d4f5e9SEd Schouten fdevname(int fd)
50 26d4f5e9SEd Schouten {
51 26d4f5e9SEd Schouten 	static char buf[SPECNAMELEN + 1];
52 26d4f5e9SEd Schouten 
53 26d4f5e9SEd Schouten 	return (fdevname_r(fd, buf, sizeof(buf)));
54 26d4f5e9SEd Schouten }
55