xref: /original-bsd/lib/libc/gen/devname.c (revision b30b9691)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)devname.c	5.11 (Berkeley) 02/08/91";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <fcntl.h>
14 #include <ndbm.h>
15 #include <stdio.h>
16 #include <paths.h>
17 
18 char *
19 devname(dev)
20 	dev_t dev;
21 {
22 	static DBM *db;
23 	static int failure;
24 	datum dp, key;
25 
26 	if (!db && !failure && !(db = dbm_open(_PATH_DEVDB, O_RDONLY, 0))) {
27 		(void)fprintf(stderr,
28 		    "ps: no device database %s\n", _PATH_DEVDB);
29 		failure = 1;
30 	}
31 	if (failure)
32 		return("??");
33 
34 	key.dptr = (char *)&dev;
35 	key.dsize = sizeof(dev);
36 	dp = dbm_fetch(db, key);
37 	return(dp.dptr ? dp.dptr : "??");
38 }
39