Licensing Information
Open Source Used In Cisco FXOS 1.1(4) 961
if (ofs_write(tdb, offset, &rec.next) == -1) {
goto fail;
}
} else {
lastrec.next = rec.next;
if (rec_write(tdb, last_ptr, &lastrec) == -1) {
goto fail;
}
}
/* all done - return the new record offset */
tdb_unlock(tdb, -1);
return rec_ptr;
}
/* move to the next record */
lastrec = rec;
last_ptr = rec_ptr;
rec_ptr = rec.next;
}
/* we didn't find enough space. See if we can expand the
database and if we can then try again */
if (tdb_expand(tdb, length + sizeof(rec)) == 0) goto again;
fail:
#if TDB_DEBUG
printf("tdb_allocate failed for size %u\n", length);
#endif
tdb_unlock(tdb, -1);
return 0;
}
/* initialise a new database with a specified hash size */
static int tdb_new_database(TDB_CONTEXT *tdb, int hash_size)
{
struct tdb_header header;
tdb_off offset;
int i, size = 0;
tdb_off buf[16];
/* create the header */
memset(&header, 0, sizeof(header));
memcpy(header.magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1);
header.version = TDB_VERSION;
header.hash_size = hash_size;
lseek(tdb->fd, 0, SEEK_SET);
ftruncate(tdb->fd, 0);