From 1f2de0ef9f648f2efea7f6bc637963c97c8085f1 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Thu, 27 Aug 1998 06:42:17 +0000 Subject: re-initialize the tty buffer with "/dev/" everytime through; spotted by d --- lib/libc/gen/ttyname.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'lib/libc/gen/ttyname.c') diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c index 0c965085e76..192072a208f 100644 --- a/lib/libc/gen/ttyname.c +++ b/lib/libc/gen/ttyname.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: ttyname.c,v 1.4 1997/07/09 00:28:25 millert Exp $"; +static char rcsid[] = "$OpenBSD: ttyname.c,v 1.5 1998/08/27 06:42:16 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -45,7 +45,7 @@ static char rcsid[] = "$OpenBSD: ttyname.c,v 1.4 1997/07/09 00:28:25 millert Exp #include #include -static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; +static char buf[sizeof(_PATH_DEV) + MAXNAMLEN]; static char *oldttyname __P((int, struct stat *)); char * @@ -68,6 +68,8 @@ ttyname(fd) if (fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) return (NULL); + memcpy(buf, _PATH_DEV, sizeof(_PATH_DEV)); + if ((db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) { memset(&bkey, 0, sizeof(bkey)); bkey.type = S_IFCHR; @@ -75,8 +77,8 @@ ttyname(fd) key.data = &bkey; key.size = sizeof(bkey); if (!(db->get)(db, &key, &data, 0)) { - bcopy(data.data, - buf + sizeof(_PATH_DEV) - 1, data.size); + memcpy(buf + sizeof(_PATH_DEV) - 1, data.data, + data.size); (void)(db->close)(db); return (buf); } @@ -101,7 +103,7 @@ oldttyname(fd, sb) while ((dirp = readdir(dp))) { if (dirp->d_fileno != sb->st_ino) continue; - bcopy(dirp->d_name, buf + sizeof(_PATH_DEV) - 1, + memcpy(buf + sizeof(_PATH_DEV) - 1, dirp->d_name, dirp->d_namlen + 1); if (stat(buf, &dsb) || sb->st_dev != dsb.st_dev || sb->st_ino != dsb.st_ino) -- cgit v1.2.3