Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen Get rid of the private getptsname() function an...



details:   https://anonhg.NetBSD.org/src/rev/c4176a91106b
branches:  trunk
changeset: 572071:c4176a91106b
user:      atatat <atatat%NetBSD.org@localhost>
date:      Thu Dec 16 04:15:19 2004 +0000

description:
Get rid of the private getptsname() function and use getdevmajor()
instead.  It's really much better that way, you'll see.

diffstat:

 lib/libc/gen/devname.c |  42 ++++++------------------------------------
 1 files changed, 6 insertions(+), 36 deletions(-)

diffs (91 lines):

diff -r 5192e4adb950 -r c4176a91106b lib/libc/gen/devname.c
--- a/lib/libc/gen/devname.c    Thu Dec 16 04:11:22 2004 +0000
+++ b/lib/libc/gen/devname.c    Thu Dec 16 04:15:19 2004 +0000
@@ -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 <sys/types.h>
+#include <sys/stat.h>
 #include <sys/param.h>
 
 #include <db.h>
-#include <dirent.h>
 #include <fcntl.h>
 #include <paths.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <err.h>
-#include <sys/stat.h>
 
 #ifdef __weak_alias
 __weak_alias(devname,_devname)
@@ -107,34 +106,6 @@
        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 @@
        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 @@
                        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));



Home | Main Index | Thread Index | Old Index