define new library function getgrouplist
[unix-history] / usr / src / lib / libc / gen / devname.c
/*
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* %sccs.include.redist.c%
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)devname.c 5.15 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
#include <db.h>
#include <stdio.h>
#include <paths.h>
char *
devname(dev, type)
dev_t dev;
mode_t type;
{
struct {
mode_t type;
dev_t dev;
} bkey;
static DB *db;
static int failure;
DBT data, key;
if (!db && !failure &&
!(db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL))) {
(void)fprintf(stderr,
"warning: %s: %s\n", _PATH_DEVDB, strerror(errno));
failure = 1;
}
if (failure)
return("??");
/*
* Keys are a mode_t followed by a dev_t. The former is the type of
* the file (mode & S_IFMT), the latter is the st_rdev field.
*/
bkey.dev = dev;
bkey.type = type;
key.data = &bkey;
key.size = sizeof(bkey);
return((db->get)(db, &key, &data, 0L) ? "??" : (char *)data.data);
}