1188497Sed/*-
2188497Sed * Copyright (c) 2009 Ed Schouten <ed@FreeBSD.org>
3188497Sed * All rights reserved.
4188497Sed *
5188497Sed * Redistribution and use in source and binary forms, with or without
6188497Sed * modification, are permitted provided that the following conditions
7188497Sed * are met:
8188497Sed * 1. Redistributions of source code must retain the above copyright
9188497Sed *    notice, this list of conditions and the following disclaimer.
10188497Sed * 2. Redistributions in binary form must reproduce the above copyright
11188497Sed *    notice, this list of conditions and the following disclaimer in the
12188497Sed *    documentation and/or other materials provided with the distribution.
13188497Sed *
14188497Sed * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15188497Sed * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16188497Sed * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17188497Sed * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18188497Sed * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19188497Sed * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20188497Sed * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21188497Sed * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22188497Sed * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23188497Sed * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24188497Sed * SUCH DAMAGE.
25188497Sed */
26188497Sed
27188497Sed#include <sys/cdefs.h>
28188497Sed__FBSDID("$FreeBSD$");
29188497Sed
30188497Sed#include "namespace.h"
31188497Sed#include <sys/param.h>
32188497Sed#include <sys/ioctl.h>
33200133Sed#include <stdlib.h>
34188497Sed#include "un-namespace.h"
35188497Sed
36188497Sedchar *
37188497Sedfdevname_r(int fd, char *buf, int len)
38188497Sed{
39188497Sed	struct fiodgname_arg fgn;
40188497Sed
41188497Sed	fgn.buf = buf;
42188497Sed	fgn.len = len;
43188497Sed
44188497Sed	if (_ioctl(fd, FIODGNAME, &fgn) == -1)
45188497Sed		return (NULL);
46188497Sed	return (buf);
47188497Sed}
48188497Sed
49188497Sedchar *
50188497Sedfdevname(int fd)
51188497Sed{
52188497Sed	static char buf[SPECNAMELEN + 1];
53188497Sed
54188497Sed	return (fdevname_r(fd, buf, sizeof(buf)));
55188497Sed}
56