* Copyright (c) 1988 The Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)ttyname.c 5.14 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
static char buf
[sizeof(_PATH_DEV
) + MAXNAMLEN
] = _PATH_DEV
;
static char *oldttyname
__P((int, struct stat
*));
/* Must be a terminal. */
if (ioctl(fd
, TIOCGETP
, &ttyb
) < 0)
/* Must be a character device. */
if (fstat(fd
, &sb
) || !S_ISCHR(sb
.st_mode
))
if (db
= dbopen(_PATH_DEVDB
, O_RDONLY
, 0, DB_HASH
, NULL
)) {
if (!(db
->get
)(db
, &key
, &data
, 0)) {
buf
+ sizeof(_PATH_DEV
) - 1, data
.size
);
return (oldttyname(fd
, &sb
));
register struct dirent
*dirp
;
if ((dp
= opendir(_PATH_DEV
)) == NULL
)
while (dirp
= readdir(dp
)) {
if (dirp
->d_fileno
!= sb
->st_ino
)
bcopy(dirp
->d_name
, buf
+ sizeof(_PATH_DEV
) - 1,
if (stat(buf
, &dsb
) || sb
->st_dev
!= dsb
.st_dev
||
sb
->st_ino
!= dsb
.st_ino
)