xref: /csrg-svn/lib/libc/gen/devname.c (revision 46337)
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*46337Sbostic static char sccsid[] = "@(#)devname.c	5.10 (Berkeley) 02/08/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>
16*46337Sbostic #include <paths.h>
1740258Smarc 
1840258Smarc char *
1946325Sbostic devname(dev)
2040258Smarc 	dev_t dev;
2140258Smarc {
2246325Sbostic 	static DBM *db;
2346325Sbostic 	static int failure;
2446325Sbostic 	datum dp, key;
2540258Smarc 
2646325Sbostic 	if (!db && !(db = dbm_open(_PATH_DEVDB, O_RDONLY, 0))) {
2746325Sbostic 		(void)fprintf(stderr,
2846325Sbostic 		    "ps: no device database %s\n", _PATH_DEVDB);
2946325Sbostic 		failure = 1;
3040258Smarc 	}
3146325Sbostic 	if (failure)
3246325Sbostic 		return("??");
3340258Smarc 
3446325Sbostic 	key.dptr = (char *)&dev;
3546325Sbostic 	key.dsize = sizeof(dev);
3646325Sbostic 	dp = dbm_fetch(db, key);
3746325Sbostic 	return(dp.dptr ? dp.dptr : "??");
3840258Smarc }
39