Ejemplo n.º 1
0
int main(int argc)
{
  DB *dbp;
  DB_INFO dbinfo;
  DB_ENV dbenv;
  int ret = 0, delta = 1, j, i;
  u_int32_t key = 0, data = 0;

  memset(&dbenv, 0, sizeof(DB_ENV));
  if ((errno = db_appinit(DATAHOME, NULL, &dbenv,
                          DB_CREATE|DB_INIT_LOCK|DB_INIT_MPOOL)) != 0) {
#error "[PM] 4.0 strerror is not thread safe. use strerror_r instead"
    fprintf(stderr, "db: %s: %s\n", DATAHOME, strerror(errno));
    return 1;
  }

  if ((errno = LOCK_DETECT(dbenv, dbenv.lk_info, DB_LOCK_CONFLICT, 0)) != 0) {
#error "[PM] 4.0 strerror is not thread safe. use strerror_r instead"
    fprintf(stderr, "db: %s\n", strerror(errno));
    ret = 1;
    goto exit;
  }

  memset(&dbinfo, 0, sizeof(DB_INFO));
  dbinfo.h_hash = identity;
  if (argc > 1) {
    /* sorting speeds up things (3/4), which is quite a wonder */
    dbinfo.flags = DB_DUP|DB_DUPSORT;
    delta = 0;
    fprintf(stderr, "storing duplicates...\n");
  }

  if ((errno = db_open(DATABASE, DB_HASH, DB_CREATE, 0664,
                       &dbenv, &dbinfo, &dbp)) != 0) {
#error "[PM] 4.0 strerror is not thread safe. use strerror_r instead"
    fprintf(stderr, "db: %s: %s\n", DATABASE, strerror(errno));
    ret = 1;
    goto exit;
  }

  for (j = 1; j <= MAX_KEYL; ++j)
    STAT(for (i = 1; i <= MAX_KEYN; ++i, key += delta, ++data)
         if (put(dbp, i, key, data)) goto close_db,
         fprintf(stderr, "#%.3d: ", j));

close_db:
  if ((errno = dbp->close(dbp, 0)) != 0) {
    fprintf(stderr, "db: close: %s\n", strerror(errno)); /* [PM] strerror not thread safe (but not using threads here) */
    ret = 1;
  }

exit:
  db_appexit(&dbenv);
  return ret;
}
Ejemplo n.º 2
0
int ldbm_shutdown( void )
{
	if( !ldbm_initialized ) return 1;

#if DB_VERSION_MAJOR < 3
	db_appexit( ldbm_Env );
#endif

	LDBM_RWLOCK_DESTROY;
	return 0;
}
Ejemplo n.º 3
0
void
dbtp_env_close(DBTPD * dbtp)
{
  if (dbtp->dbenv != NULL) {
#if DB_VERSION_MAJOR == 2
    dbtp->dberr = db_appexit(dbtp->dbenv);
#else	/* DB_VERSION_MAJOR > 2	*/
    dbtp->dberr = dbtp->dbenv->close(dbtp->dbenv, 0);
#endif
  }
  dbtp->dbenv = NULL;
}