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.13 (Berkeley) 03/03/91"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <sys/types.h> 13 #include <fcntl.h> 14 #include <db.h> 15 #include <stdio.h> 16 #include <paths.h> 17 18 char * 19 devname(dev) 20 dev_t dev; 21 { 22 static DB *db; 23 static int failure; 24 DBT data, key; 25 26 if (!db && !failure && 27 !(db = hash_open(_PATH_DEVDB, O_RDONLY, 0, NULL))) { 28 (void)fprintf(stderr, 29 "ps: no device database %s\n", _PATH_DEVDB); 30 failure = 1; 31 } 32 if (failure) 33 return("??"); 34 35 key.data = (u_char *)&dev; 36 key.size = sizeof(dev); 37 return((db->get)(db, &key, &data, 0L) ? "??" : (char *)data.data); 38 } 39