Commit | Line | Data |
---|---|---|
25594745 MT |
1 | /* |
2 | * Copyright (c) 1989 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
27c71911 | 5 | * %sccs.include.redist.c% |
25594745 MT |
6 | */ |
7 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | |
580ce8b5 | 9 | static char sccsid[] = "@(#)devname.c 5.13 (Berkeley) %G%"; |
25594745 MT |
10 | #endif /* LIBC_SCCS and not lint */ |
11 | ||
89962e19 | 12 | #include <sys/types.h> |
fd57c467 | 13 | #include <fcntl.h> |
580ce8b5 | 14 | #include <db.h> |
b5bb6e20 | 15 | #include <stdio.h> |
c9ccd93d | 16 | #include <paths.h> |
89962e19 MT |
17 | |
18 | char * | |
fd57c467 | 19 | devname(dev) |
89962e19 MT |
20 | dev_t dev; |
21 | { | |
9bce4f97 | 22 | static DB *db; |
fd57c467 | 23 | static int failure; |
9bce4f97 | 24 | DBT data, key; |
fd57c467 | 25 | |
9bce4f97 KB |
26 | if (!db && !failure && |
27 | !(db = hash_open(_PATH_DEVDB, O_RDONLY, 0, NULL))) { | |
fd57c467 KB |
28 | (void)fprintf(stderr, |
29 | "ps: no device database %s\n", _PATH_DEVDB); | |
30 | failure = 1; | |
89962e19 | 31 | } |
fd57c467 KB |
32 | if (failure) |
33 | return("??"); | |
89962e19 | 34 | |
9bce4f97 KB |
35 | key.data = (u_char *)&dev; |
36 | key.size = sizeof(dev); | |
37 | return((db->get)(db, &key, &data, 0L) ? "??" : (char *)data.data); | |
89962e19 | 38 | } |