xref: /csrg-svn/lib/libc/gen/devname.c (revision 46943)
140966Smarc /*
240966Smarc  * Copyright (c) 1989 The Regents of the University of California.
340966Smarc  * All rights reserved.
440966Smarc  *
542537Sbostic  * %sccs.include.redist.c%
640966Smarc  */
740966Smarc 
840966Smarc #if defined(LIBC_SCCS) && !defined(lint)
9*46943Sbostic static char sccsid[] = "@(#)devname.c	5.12 (Berkeley) 03/03/91";
1040966Smarc #endif /* LIBC_SCCS and not lint */
1140966Smarc 
1240258Smarc #include <sys/types.h>
1346325Sbostic #include <fcntl.h>
1446325Sbostic #include <ndbm.h>
1545158Smarc #include <stdio.h>
1646337Sbostic #include <paths.h>
1740258Smarc 
1840258Smarc char *
1946325Sbostic devname(dev)
2040258Smarc 	dev_t dev;
2140258Smarc {
22*46943Sbostic 	static DB *db;
2346325Sbostic 	static int failure;
24*46943Sbostic 	DBT data, key;
2540258Smarc 
26*46943Sbostic 	if (!db && !failure &&
27*46943Sbostic 	    !(db = hash_open(_PATH_DEVDB, O_RDONLY, 0, NULL))) {
2846325Sbostic 		(void)fprintf(stderr,
2946325Sbostic 		    "ps: no device database %s\n", _PATH_DEVDB);
3046325Sbostic 		failure = 1;
3140258Smarc 	}
3246325Sbostic 	if (failure)
3346325Sbostic 		return("??");
3440258Smarc 
35*46943Sbostic 	key.data = (u_char *)&dev;
36*46943Sbostic 	key.size = sizeof(dev);
37*46943Sbostic 	return((db->get)(db, &key, &data, 0L) ? "??" : (char *)data.data);
3840258Smarc }
39