Licensing Information

Open Source Used In Cisco FXOS 1.1(3) 876
/* open the database, creating it if necessary
The open_flags and mode are passed straight to the open call on the database
file. A flags value of O_WRONLY is invalid
The hash size is advisory, use zero for a default value.
return is NULL on error
*/
TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags,
 int open_flags, mode_t mode)
{
TDB_CONTEXT tdb, *ret;
struct stat st;
memset(&tdb, 0, sizeof(tdb));
tdb.fd = -1;
tdb.name = NULL;
tdb.map_ptr = NULL;
if ((open_flags & O_ACCMODE) == O_WRONLY) {
goto fail;
}
if (hash_size == 0) hash_size = DEFAULT_HASH_SIZE;
tdb.read_only = ((open_flags & O_ACCMODE) == O_RDONLY);
if (name != NULL) {
tdb.fd = open(name, open_flags, mode);
if (tdb.fd == -1) {
goto fail;
}
}
/* ensure there is only one process initialising at once */
tdb_brlock(&tdb, GLOBAL_LOCK, LOCK_SET, F_WRLCK, F_SETLKW);
if (tdb_flags & TDB_CLEAR_IF_FIRST) {
/* we need to zero the database if we are the only
 one with it open */
if (tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_SET, F_WRLCK, F_SETLK) == 0) {
ftruncate(tdb.fd, 0);
tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_CLEAR, F_WRLCK, F_SETLK);
}
}