Licensing Information

Open Source Used In Cisco FXOS 1.1(3) 874
return 0 on success, -1 on failure
*/
int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag)
{
struct list_struct rec;
unsigned hash;
tdb_off rec_ptr, offset;
char *p = NULL;
info("Enter: tdb_store.");
if (tdb == NULL) {
#ifdef TDB_DEBUG
printf("tdb_store() called with null context\n");
#endif
return -1;
}
/* find which hash bucket it is in */
hash = tdb_hash(&key);
/* check for it existing */
if (flag == TDB_INSERT && tdb_exists(tdb, key)) {
tdb->ecode = TDB_ERR_EXISTS;
return -1;
}
info("tdb_store: calling tdb_update.");
/* first try in-place update */
if (flag != TDB_INSERT && tdb_update(tdb, key, dbuf) == 0) {
return 0;
}
rec_ptr = tdb_allocate(tdb, key.dsize + dbuf.dsize);
if (rec_ptr == 0) {
return -1;
}
tdb_lock(tdb, BUCKET(hash));
/* delete any existing record - if it doesn't exist we don't care */
if (flag != TDB_INSERT) {
tdb_delete(tdb, key);
}
/* read the newly created record */
if (tdb_read(tdb, rec_ptr, (char *)&rec, sizeof(rec)) == -1) {
goto fail;
}