Licensing Information
Open Source Used In Cisco FXOS 1.1(4) 973
/* 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;
}
if (rec.magic != TDB_FREE_MAGIC) goto fail;
/* find the top of the hash chain */
offset = tdb_hash_top(tdb, hash);
/* read in the hash top diretcly into our next pointer */
if (ofs_read(tdb, offset, &rec.next) == -1) {
goto fail;
}
rec.key_len = key.dsize;
rec.data_len = dbuf.dsize;
rec.full_hash = hash;
rec.magic = TDB_MAGIC;
p = (char *)malloc(sizeof(rec) + key.dsize + dbuf.dsize);
if (!p) {
tdb->ecode = TDB_ERR_OOM;