* Copyright (c) 1983 Eric P. Allman
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char copyright
[] =
"@(#) Copyright (c) 1988, 1993\n\
The Regents of the University of California. All rights reserved.\n";
static char sccsid
[] = "@(#)praliases.c 8.3 (Berkeley) %G%";
DBT newdbkey
, newdbcontent
;
filename
= "/etc/aliases";
while ((ch
= getopt(argc
, argv
, "f:")) != EOF
)
(void)fprintf(stderr
, "usage: praliases [-f file]\n");
(void) strcpy(buf
, filename
);
(void) strcat(buf
, ".db");
if (db
= dbopen(buf
, O_RDONLY
, 0444 , DB_HASH
, NULL
)) {
while(!db
->seq(db
, &newdbkey
, &newdbcontent
, R_NEXT
))
newdbkey
.size
, newdbkey
.data
,
newdbcontent
.size
, newdbcontent
.data
);
else for (; *argv
; ++argv
) {
newdbkey
.size
= strlen(*argv
) + 1;
if (!db
->get(db
, &newdbkey
, &newdbcontent
, 0))
printf("%s:%.*s\n", newdbkey
.data
,
newdbcontent
.size
, newdbcontent
.data
);
printf("%s: No such key\n",
if ((dbp
= dbm_open(filename
, O_RDONLY
, 0)) == NULL
) {
"praliases: %s: %s\n", filename
, strerror(errno
));
for (key
= dbm_firstkey(dbp
);
key
.dptr
!= NULL
; key
= dbm_nextkey(dbp
)) {
content
= dbm_fetch(dbp
, key
);
(void)printf("%.*s:%.*s\n",
content
.dsize
, content
.dptr
);
else for (; *argv
; ++argv
) {
key
.dsize
= strlen(*argv
) + 1;
content
= dbm_fetch(dbp
, key
);
(void)printf("%s: No such key\n", key
.dptr
);
(void)printf("%s:%.*s\n", key
.dptr
,
content
.dsize
, content
.dptr
);