home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume21
/
amd
/
part01
/
info_ndbm.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-10
|
2KB
|
98 lines
/*
* $Id: info_ndbm.c,v 5.1.1.1 89/11/28 17:47:20 jsp Exp Locker: jsp $
*
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Imperial College of Science, Technology and Medicine, London, UK.
* The names of the College and University may not be used to endorse
* or promote products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* %W% (Berkeley) %G%
*/
/*
* Get info from NDBM map
*/
#include "am.h"
#ifdef HAS_NDBM_MAPS
#include <ndbm.h>
#include <fcntl.h>
#include <sys/stat.h>
static int search_ndbm(db, key, val)
DBM *db;
char *key;
char **val;
{
datum k, v;
k.dptr = key;
k.dsize = strlen(key) + 1;
v = dbm_fetch(db, k);
if (v.dptr) {
*val = strdup(v.dptr);
return 0;
}
return ENOENT;
}
int ndbm_search(m, map, key, pval, tp)
mnt_map *m;
char *map;
char *key;
char **pval;
time_t *tp;
{
DBM *db;
db = dbm_open(map, O_RDONLY, 0);
if (db) {
struct stat stb;
int error;
error = fstat(dbm_pagfno(db), &stb);
if (!error && *tp < stb.st_mtime) {
*tp = stb.st_mtime;
error = -1;
} else {
error = search_ndbm(db, key, pval);
}
(void) dbm_close(db);
return error;
}
return errno;
}
int ndbm_init(map)
char *map;
{
DBM *db;
db = dbm_open(map, O_RDONLY, 0);
if (db) {
dbm_close(db);
return 0;
}
return errno;
}
#endif