* use berkeley db btree or hash package *
* *
*****************************************************************/
-
#include <sys/types.h>
#include <limits.h>
#include <fcntl.h>
#ifdef HAVE_DB_185_H
# include <db_185.h>
+#ifndef DB_VERSION_MAJOR
+# define DB_VERSION_MAJOR 1
+#endif
+#ifndef DB_VERSION_MINOR
+# define DB_VERSION_MINOR 85
+#endif
#else
# ifdef HAVE_DB1_DB_H
# include <db1/db.h>
# else
# include <db.h>
# endif
-# if defined( HAVE_BERKELEY_DB2 ) || ( HAVE_BERKELEY_DB3 )
+# if DB_VERSION_MAJOR >= 2
# define R_NOOVERWRITE DB_NOOVERWRITE
# ifndef DEFAULT_DB_PAGE_SIZE
# define DEFAULT_DB_PAGE_SIZE 4096
/* for ldbm_open */
-#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 2
typedef DBC LDBMCursor;
# define LDBM_READER DB_RDONLY
# define LDBM_WRITER 0x00000 /* hopefully */
-# if defined( HAVE_BERKELEY_DB2_DB_THREAD ) || defined( HAVE_BERKELEY_DB3_DB_THREAD )
+# if defined( HAVE_BERKELEY_DB_THREAD )
# define LDBM_WRCREAT (DB_NOMMAP|DB_CREATE|DB_THREAD)
# define LDBM_NEWDB (DB_TRUNCATE|DB_CREATE|DB_THREAD)
# else
LIBLDBM_F (Datum) ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *cursor );
/* initialization of Datum structures */
-#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
+#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2)
LIBLDBM_F (void *) ldbm_malloc( size_t size );
# define ldbm_datum_init(d) ((void)memset(&(d), 0, sizeof(Datum)))
#else
# define ldbm_datum_init(d) ((void)0)
-#endif /* HAVE_BERKELEY_DB2 */
+#endif /* HAVE_BERKELEY_DB */
LDAP_END_DECL
static int ldbm_initialized = 0;
-#if defined( HAVE_BERKELEY_DB2_DB_THREAD ) || defined( HAVE_BERKELEY_DB3_DB_THREAD )
+#if defined( HAVE_BERKELEY_DB_THREAD ) || defined( HAVE_BERKELEY_DB_THREAD )
#define LDBM_LOCK ((void)0)
#define LDBM_UNLOCK ((void)0)
#else
#endif
-#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
+
+/*******************************************************************
+ * *
+ * Create some special functions to initialize Berkeley DB for *
+ * versions greater than 2. *
+ * *
+ *******************************************************************/
+#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 2)
void *
ldbm_Env->db_errpfx = "==>";
envFlags = DB_CREATE
-#if defined( HAVE_BERKELEY_DB2_DB_THREAD ) || defined( HAVE_BERKELEY_DB3_DB_THREAD )
+#if defined( HAVE_BERKELEY_DB_THREAD )
| DB_THREAD
#endif
;
if (
-#if defined( HAVE_BERKELEY_DB2 )
- ( err = db_appinit( NULL, NULL, ldbm_Env, envFlags ))
-#elif defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 3
( err = db_env_create( &ldbm_Env, 0))
+#elif DB_VERSION_MAJOR >= 2
+ ( err = db_appinit( NULL, NULL, ldbm_Env, envFlags ))
#endif
)
{
#endif
return( 1 );
}
-#if defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 3
envFlags |= DB_INIT_MPOOL;
err = ldbm_Env->open( ldbm_Env, NULL, NULL, envFlags, 0 );
if ( err != 0 )
{
if( !ldbm_initialized ) return 1;
-# ifdef HAVE_BERKELEY_DB3
+#if DB_VERSION_MAJOR >= 3
ldbm_Env->close( ldbm_Env, 0 );
#else
db_appexit( ldbm_Env );
return 0;
}
-#else
+#else /* some DB other than Berkeley V2 or greater */
int ldbm_initialize( void )
{
return 0;
}
-#endif
+#endif /* ifdef HAVE_BERKELEY_DB */
+
#if defined( LDBM_USE_DBHASH ) || defined( LDBM_USE_DBBTREE )
{
LDBM ret = NULL;
-#if defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 3
int err;
LDBM_LOCK;
err = db_create( &ret, ldbm_Env, 0 );
return NULL;
}
-#elif defined( HAVE_BERKELEY_DB2 )
+#elif DB_VERSION_MAJOR >= 2
DB_INFO dbinfo;
memset( &dbinfo, 0, sizeof( dbinfo ));
ldbm_close( LDBM ldbm )
{
LDBM_LOCK;
-#if defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 3
ldbm->close( ldbm, 0 );
-#elif defined( HAVE_BERKELEY_DB2 )
+#elif DB_VERSION_MAJOR >= 2
(*ldbm->close)( ldbm, 0 );
#else
(*ldbm->close)( ldbm );
int rc;
LDBM_LOCK;
-#if defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 3
ldbm_datum_init( data );
data.flags = DB_DBT_MALLOC;
if ( (rc = ldbm->get( ldbm, NULL, &key, &data, 0 )) != 0 ) {
ldbm_datum_free( ldbm, data );
-#elif defined( HAVE_BERKELEY_DB2 )
+#elif DB_VERSION_MAJOR >= 2
ldbm_datum_init( data );
data.flags = DB_DBT_MALLOC;
LDBM_LOCK;
-#if defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 3
rc = ldbm->put( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC );
if ( rc != 0 )
{
}
rc = (-1) * rc;
-#elif defined( HAVE_BERKELEY_DB2 )
+#elif DB_VERSION_MAJOR >= 2
rc = (*ldbm->put)( ldbm, NULL, &key, &data, flags & ~LDBM_SYNC );
rc = (-1 ) * rc;
#else
LDBM_LOCK;
-#if defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 3
rc = ldbm->del( ldbm, NULL, &key, 0 );
rc = (-1 ) * rc;
-#elif defined( HAVE_BERKELEY_DB2 )
+#elif DB_VERSION_MAJOR >= 2
rc = (*ldbm->del)( ldbm, NULL, &key, 0 );
rc = (-1 ) * rc;
#else
{
Datum key, data;
-#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 2
LDBMCursor *dbci;
ldbm_datum_init( key );
LDBM_LOCK;
/* acquire a cursor for the DB */
-# if defined( HAVE_BERKELEY_DB3 )
+# if DB_VERSION_MAJOR >= 3
if ( ldbm->cursor( ldbm, NULL, &dbci, 0 ) )
# elif defined( DB_VERSION_MAJOR ) && defined( DB_VERSION_MINOR ) && \
(DB_VERSION_MAJOR == 2 && DB_VERSION_MINOR < 6)
key.dsize = 0;
}
-#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 2
}
#endif
{
Datum data;
-#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
+#if DB_VERSION_MAJOR >= 2
ldbm_datum_init( data );
ldbm_datum_free( ldbm, key );