Licensing Information

Open Source Used In Cisco FXOS 1.1(3) 858
/* read a lump of data at a specified offset */
static int tdb_read(TDB_CONTEXT *tdb, tdb_off offset, char *buf, tdb_len len)
{
if (tdb_oob(tdb, offset + len) != 0) {
/* oops - trying to read beyond the end of the database! */
return -1;
}
if (tdb->map_ptr) {
memcpy(buf, offset + (char *)tdb->map_ptr, len);
} else {
if (lseek(tdb->fd, offset, SEEK_SET) != offset ||
 read(tdb->fd, buf, len) != (ssize_t)len) {
tdb->ecode = TDB_ERR_IO;
return -1;
}
}
return 0;
}
/* read a lump of data, allocating the space for it */
static char *tdb_alloc_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_len len)
{
char *buf;
buf = (char *)malloc(len);
if (!buf) {
tdb->ecode = TDB_ERR_OOM;
return NULL;
}
if (tdb_read(tdb, offset, buf, len) == -1) {
free(buf);
return NULL;
}
return buf;
}
/* convenience routine for writing a record */
static int rec_write(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec)
{
return tdb_write(tdb, offset, (char *)rec, sizeof(*rec));
}