/* ldbm.c - ldap dbm compatibility routines */
+/* $OpenLDAP$ */
/*
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
static int ldbm_initialized = 0;
-#ifndef HAVE_BERKELEY_DB2
-/* Everything but DB2 is non-reentrant */
-
+#ifndef HAVE_BERKELEY_DB2_DB_THREAD
+/* Only DB2 with DB_THREAD is thread-free */
static ldap_pvt_thread_mutex_t ldbm_big_mutex;
#define LDBM_LOCK (ldap_pvt_thread_mutex_lock(&ldbm_big_mutex))
#define LDBM_UNLOCK (ldap_pvt_thread_mutex_unlock(&ldbm_big_mutex))
+#else
+#define LDBM_LOCK ((void)0)
+#define LDBM_UNLOCK ((void)0)
+#endif
+
+#ifndef HAVE_BERKELEY_DB2
+
int ldbm_initialize( void )
{
if(ldbm_initialized++) return 1;
static DB_ENV ldbm_Env_internal;
DB_ENV *ldbm_Env = NULL;
-/* Berkeley DB 2.x is reentrant */
-#define LDBM_LOCK ((void)0)
-#define LDBM_UNLOCK ((void)0)
-
int ldbm_initialize( void )
{
int err;
- int envFlags;
+ u_int32_t envFlags;
if(ldbm_initialized++) return 1;
ldbm_Env->db_errcall = ldbm_db_errcall;
ldbm_Env->db_errpfx = "==>";
- envFlags = DB_CREATE | DB_THREAD;
+ envFlags = DB_CREATE
+#ifdef HAVE_BERKELEY_DB2_DB_THREAD
+ | DB_THREAD
+#endif
+ ;
if ( ( err = db_appinit( NULL, NULL, ldbm_Env, envFlags )) ) {
char error[BUFSIZ];
#ifdef HAVE_ST_BLKSIZE
if ( dbcachesize > 0 && stat( name, &st ) == 0 ) {
- dbcachesize = (dbcachesize / st.st_blksize);
+ dbcachesize /= st.st_blksize;
+ if( dbcachesize == 0 ) dbcachesize = 1;
gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
}
#else
- dbcachesize = (dbcachesize / 4096);
- gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
+ if ( dbcachesize > 0 ) {
+ dbcachesize /= 4096;
+ if( dbcachesize == 0 ) dbcachesize = 1;
+ gdbm_setopt( db, GDBM_CACHESIZE, &dbcachesize, sizeof(int) );
+ }
#endif
LDBM_UNLOCK;