* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)devname.c 5.4 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#define hash(x) ((x)&0xff)
static struct devs
*devhash
[0xff];
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));