Licensing Information
Open Source Used In Cisco FXOS 1.1(4) 966
/* check if an entry in the database exists
note that 1 is returned if the key is found and 0 is returned if not found
this doesn't match the conventions in the rest of this module, but is
compatible with gdbm
*/
int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key)
{
unsigned hash;
tdb_off rec_ptr;
struct list_struct rec;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_exists() called with null context\n");
#endif
return 0;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
tdb_lock(tdb, BUCKET(hash));
rec_ptr = tdb_find(tdb, key, hash, &rec);
tdb_unlock(tdb, BUCKET(hash));
return rec_ptr != 0;
}
/* traverse the entire database - calling fn(tdb, key, data) on each element.
return -1 on error or the record count traversed
if fn is NULL then it is not called
a non-zero return value from fn() indicates that the traversal should stop
*/
int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf,
void* state), void* state)
{
int count = 0;
unsigned h;
tdb_off offset, rec_ptr;
struct list_struct rec;
char *data;
TDB_DATA key, dbuf;
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_traverse() called with null context\n");