Get rid of the private getptsname() function and use getdevmajor()
instead. It's really much better that way, you'll see.
This commit is contained in:
parent
16cc80a689
commit
4e04a6f62d
|
@ -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 @@ 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));
|
||||
|
|
Loading…
Reference in New Issue