From 4e04a6f62def94c2417c239ea5154cad76a7289a Mon Sep 17 00:00:00 2001 From: atatat Date: Thu, 16 Dec 2004 04:15:19 +0000 Subject: [PATCH] Get rid of the private getptsname() function and use getdevmajor() instead. It's really much better that way, you'll see. --- lib/libc/gen/devname.c | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c index f7f2edb897fd..1818995e226f 100644 --- a/lib/libc/gen/devname.c +++ b/lib/libc/gen/devname.c @@ -1,4 +1,4 @@ -/* $NetBSD: devname.c,v 1.14 2004/12/14 03:08:01 atatat Exp $ */ +/* $NetBSD: devname.c,v 1.15 2004/12/16 04:15:19 atatat Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -74,23 +74,22 @@ #if 0 static char sccsid[] = "@(#)devname.c 8.2 (Berkeley) 4/29/95"; #else -__RCSID("$NetBSD: devname.c,v 1.14 2004/12/14 03:08:01 atatat Exp $"); +__RCSID("$NetBSD: devname.c,v 1.15 2004/12/16 04:15:19 atatat Exp $"); #endif #endif /* LIBC_SCCS and not lint */ #include "namespace.h" #include +#include #include #include -#include #include #include #include #include #include #include -#include #ifdef __weak_alias __weak_alias(devname,_devname) @@ -107,34 +106,6 @@ typedef struct devc { char name[NAME_MAX]; /* device name */ } DEVC; -static mode_t getptsmajor(void); - -static mode_t -getptsmajor(void) -{ - DIR *dirp; - struct dirent *dp; - struct stat st; - char buf[MAXPATHLEN]; - - if ((dirp = opendir(_PATH_DEV_PTS)) == NULL) - return (mode_t)~0; - - while ((dp = readdir(dirp)) != NULL) { - if (dp->d_name[0] == '.') - continue; - (void)snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV_PTS, - dp->d_name); - if (stat(buf, &st) == -1) - continue; - (void)closedir(dirp); - return major(st.st_rdev); - } - (void)closedir(dirp); - return (mode_t)~0; -} - - char * devname(dev, type) dev_t dev; @@ -149,7 +120,7 @@ devname(dev, type) DBT data, key; DEVC *ptr, **pptr; static DEVC **devtb = NULL; - static mode_t pts = 0; + dev_t pts; if (!db && !failure && @@ -202,9 +173,8 @@ devname(dev, type) return (NULL); ptr->valid = INVALID; if (type == S_IFCHR) { - if (pts == 0) - pts = getptsmajor(); - if (pts != (mode_t)~0 && major(dev) == pts) { + pts = getdevmajor("pts", S_IFCHR); + if (pts != (dev_t)~0 && major(dev) == pts) { (void)snprintf(ptr->name, sizeof(ptr->name), "%s%d", _PATH_DEV_PTS + sizeof(_PATH_DEV) - 1, minor(dev));