Use devname(3) to do the task.
Reviewed by: imp
This commit is contained in:
parent
321661dd03
commit
4d6423b947
@ -50,7 +50,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <pthread.h>
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include <db.h>
|
||||
#include "libc_private.h"
|
||||
|
||||
static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV;
|
||||
@ -77,8 +76,6 @@ ttyname(int fd)
|
||||
char *
|
||||
ttyname_r(int fd, char *buf, size_t len)
|
||||
{
|
||||
struct dirent *dirp;
|
||||
DIR *dp;
|
||||
struct stat dsb;
|
||||
struct stat sb;
|
||||
char *rval;
|
||||
@ -96,23 +93,7 @@ ttyname_r(int fd, char *buf, size_t len)
|
||||
if (len <= sizeof(_PATH_DEV))
|
||||
return (rval);
|
||||
|
||||
if ((dp = opendir(_PATH_DEV)) != NULL) {
|
||||
memcpy(buf, _PATH_DEV, sizeof(_PATH_DEV));
|
||||
for (rval = NULL; (dirp = readdir(dp)) != NULL;) {
|
||||
if (dirp->d_fileno != sb.st_ino)
|
||||
continue;
|
||||
minlen = (len - (sizeof(_PATH_DEV) - 1)) < (dirp->d_namlen + 1) ?
|
||||
(len - (sizeof(_PATH_DEV) - 1)) : (dirp->d_namlen + 1);
|
||||
memcpy(buf + sizeof(_PATH_DEV) - 1, dirp->d_name, minlen);
|
||||
if (stat(buf, &dsb) || sb.st_dev != dsb.st_dev ||
|
||||
sb.st_ino != dsb.st_ino)
|
||||
continue;
|
||||
rval = buf;
|
||||
break;
|
||||
}
|
||||
(void) closedir(dp);
|
||||
}
|
||||
return (rval);
|
||||
return(devname_r(sb.st_rdev, S_IFCHR, buf, sizeof(buf)));
|
||||
}
|
||||
|
||||
static char *
|
||||
@ -151,12 +132,6 @@ ttyname_unthreaded(int fd)
|
||||
{
|
||||
struct stat sb;
|
||||
struct termios ttyb;
|
||||
DB *db;
|
||||
DBT data, key;
|
||||
struct {
|
||||
mode_t type;
|
||||
dev_t dev;
|
||||
} bkey;
|
||||
|
||||
/* Must be a terminal. */
|
||||
if (tcgetattr(fd, &ttyb) < 0)
|
||||
@ -165,44 +140,5 @@ ttyname_unthreaded(int fd)
|
||||
if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode))
|
||||
return (NULL);
|
||||
|
||||
if ( (db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL)) ) {
|
||||
memset(&bkey, 0, sizeof(bkey));
|
||||
bkey.type = S_IFCHR;
|
||||
bkey.dev = sb.st_rdev;
|
||||
key.data = &bkey;
|
||||
key.size = sizeof(bkey);
|
||||
if (!(db->get)(db, &key, &data, 0)) {
|
||||
bcopy(data.data,
|
||||
buf + sizeof(_PATH_DEV) - 1, data.size);
|
||||
(void)(db->close)(db);
|
||||
return (buf);
|
||||
}
|
||||
(void)(db->close)(db);
|
||||
}
|
||||
return (oldttyname(fd, &sb));
|
||||
}
|
||||
|
||||
static char *
|
||||
oldttyname(int fd, struct stat *sb)
|
||||
{
|
||||
struct dirent *dirp;
|
||||
struct stat dsb;
|
||||
DIR *dp;
|
||||
|
||||
if ((dp = opendir(_PATH_DEV)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
while ( (dirp = readdir(dp)) ) {
|
||||
if (dirp->d_fileno != sb->st_ino)
|
||||
continue;
|
||||
bcopy(dirp->d_name, buf + sizeof(_PATH_DEV) - 1,
|
||||
dirp->d_namlen + 1);
|
||||
if (stat(buf, &dsb) || sb->st_dev != dsb.st_dev ||
|
||||
sb->st_ino != dsb.st_ino)
|
||||
continue;
|
||||
(void)closedir(dp);
|
||||
return (buf);
|
||||
}
|
||||
(void)closedir(dp);
|
||||
return (NULL);
|
||||
return(devname_r(sb.st_rdev, S_IFCHR, buf, sizeof(buf)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user