I'm not up to speed on the per thread magic storage thing, so I would appreciate if somebody could review & test this patch: Index: gen/ttyname.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/ttyname.c,v retrieving revision 1.12 diff -u -r1.12 ttyname.c --- gen/ttyname.c 1 Feb 2002 01:32:19 -0000 1.12 +++ gen/ttyname.c 20 Jun 2003 09:44:28 -0000 _at__at_ -50,7 +50,6 _at__at_ #include <pthread.h> #include "un-namespace.h" -#include <db.h> #include "libc_private.h" static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; _at__at_ -77,8 +76,6 _at__at_ char * ttyname_r(int fd, char *buf, size_t len) { - struct dirent *dirp; - DIR *dp; struct stat dsb; struct stat sb; char *rval; _at__at_ -96,23 +93,7 _at__at_ 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 * _at__at_ -151,12 +132,6 _at__at_ { 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) _at__at_ -165,44 +140,5 _at__at_ 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))); } -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk_at_FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence.Received on Fri Jun 20 2003 - 02:32:03 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:37:12 UTC