* Copyright (c) 1990 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)dev_mkdb.c 5.3 (Berkeley) %G%";
register struct dirent
*dp
;
char buf
[MAXNAMLEN
+ 1], dbtmp
[MAXPATHLEN
+ 1], dbname
[MAXPATHLEN
+ 1];
while ((ch
= getopt(argc
, argv
, "")) != EOF
)
(void)sprintf(dbtmp
, "%s/dev.tmp", _PATH_VARRUN
);
(void)sprintf(dbname
, "%s/dev.db", _PATH_VARRUN
);
if ((db
= dbm_open(dbtmp
, O_CREAT
|O_WRONLY
|O_EXCL
,
S_IRUSR
|S_IWUSR
|S_IRGRP
|S_IROTH
)) == NULL
)
key
.dptr
= (char *)&sb
.st_rdev
;
key
.dsize
= sizeof(sb
.st_rdev
);
while (dp
= readdir(dirp
)) {
if (stat(dp
->d_name
, &sb
))
if (!S_ISCHR(sb
.st_mode
))
/* Nul terminate the name so ps doesn't have to. */
bcopy(dp
->d_name
, buf
, dp
->d_namlen
);
buf
[dp
->d_namlen
] = '\0';
data
.dsize
= dp
->d_namlen
+ 1;
if (dbm_store(db
, key
, data
, DBM_INSERT
) < 0)
(void)strcat(dbtmp
, DBM_SUFFIX
);
if (rename(dbtmp
, dbname
)) {
(void)fprintf(stderr
, "dev_mkdb: %s to %s: %s.\n",
dbtmp
, dbname
, strerror(errno
));
(void)fprintf(stderr
, "kvm_mkdb: %s: %s\n", n
, strerror(errno
));
(void)fprintf(stderr
, "usage: dev_mkdb\n");