diff options
author | ed <ed@FreeBSD.org> | 2009-02-11 20:24:59 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-02-11 20:24:59 +0000 |
commit | de78bbbfe832781ef4718e4d175d53fbe4e7ac40 (patch) | |
tree | 0b13c353e44fe54b12f0be5c1ae687436add79ee /lib/libc/stdlib | |
parent | c1e92bfb206adffe9aca701014c9028722d1ed02 (diff) | |
download | FreeBSD-src-de78bbbfe832781ef4718e4d175d53fbe4e7ac40.zip FreeBSD-src-de78bbbfe832781ef4718e4d175d53fbe4e7ac40.tar.gz |
Add two new routines: fdevname() and fdevname_r().
A more elegant way of obtaining a name of a character device by its file
descriptor on FreeBSD, is to use the FIODGNAME ioctl. Because a valid
file descriptor implies a file descriptor is visible in /dev, it will
always resolve a valid device name.
I'm adding a more friendly wrapper for this ioctl, called fdevname(). It
is a lot easier to use than devname() and also has better error
handling. When a device name cannot be resolved, it will just return
NULL instead of a generated device name that makes no sense.
Discussed with: kib
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r-- | lib/libc/stdlib/ptsname.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/libc/stdlib/ptsname.c b/lib/libc/stdlib/ptsname.c index fa606f6..fc3b719 100644 --- a/lib/libc/stdlib/ptsname.c +++ b/lib/libc/stdlib/ptsname.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <paths.h> +#include <stdlib.h> #include "un-namespace.h" /* @@ -75,7 +76,6 @@ char * ptsname(int fildes) { static char pt_slave[sizeof _PATH_DEV + SPECNAMELEN] = _PATH_DEV; - struct fiodgname_arg fgn; char *ret = NULL; int sverrno = errno; @@ -83,10 +83,8 @@ ptsname(int fildes) if (__isptmaster(fildes) != 0) goto done; - /* Obtain the device name through FIODGNAME. */ - fgn.len = sizeof pt_slave - (sizeof _PATH_DEV - 1); - fgn.buf = pt_slave + (sizeof _PATH_DEV - 1); - if (_ioctl(fildes, FIODGNAME, &fgn) == 0) + if (fdevname_r(fildes, pt_slave + (sizeof _PATH_DEV - 1), + sizeof pt_slave - (sizeof _PATH_DEV - 1)) != NULL) ret = pt_slave; done: /* Make sure ptsname() does not overwrite errno. */ |