* Copyright (c) 1989 The Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)devname.c 5.6 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#define hash(x) ((x)&0xff)
static struct devs
*devhash
[0xff + 1];
register struct devs
*devpp
;
register struct dirent
*entry
;
DIR *dp
= opendir(_PATH_DEV
);
int savewd
= open(".", O_RDONLY
, 0);
if (savewd
== -1 || dp
== NULL
|| chdir(_PATH_DEV
) == -1)
while ((entry
= readdir(dp
)) != NULL
) {
if (stat(entry
->d_name
, &sb
) == -1)
switch(sb
.st_mode
&S_IFMT
) {
devp
= (struct devs
*)malloc(sizeof (struct devs
));
devp
->type
= specialtype
;
strcpy(devp
->name
, entry
->d_name
);
if ((devpp
= devhash
[hash(sb
.st_rdev
)]) == NULL
)
devhash
[hash(sb
.st_rdev
)] = devp
;
for (;devpp
->next
!= NULL
; devpp
= devpp
->next
)
for (devp
= devhash
[hash(dev
)]; devp
!= NULL
; devp
= devp
->next
)
if (dev
== devp
->dev
&& type
== devp
->type
)
printf(" %s \n", devname(0));