use HAVE_BERKELEY_DB and check DB_VERSION_MAJOR for differences

This commit is contained in:
Gary Williams 2000-05-25 20:41:55 +00:00
parent 862e624254
commit 780d4737af
2 changed files with 43 additions and 30 deletions

View File

@ -22,20 +22,25 @@
* 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
@ -54,12 +59,12 @@ typedef DB *LDBM;
/* 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
@ -246,12 +251,12 @@ LIBLDBM_F (Datum) ldbm_firstkey( LDBM ldbm, LDBMCursor **cursor );
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

View File

@ -58,7 +58,7 @@ ldbm_datum_dup( LDBM ldbm, Datum data )
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
@ -71,7 +71,14 @@ static ldap_pvt_thread_mutex_t ldbm_big_mutex;
#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 *
@ -110,16 +117,16 @@ int ldbm_initialize( 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
)
{
@ -137,7 +144,7 @@ int ldbm_initialize( void )
#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 )
@ -165,7 +172,7 @@ int ldbm_shutdown( void )
{
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 );
@ -174,7 +181,7 @@ int ldbm_shutdown( void )
return 0;
}
#else
#else /* some DB other than Berkeley V2 or greater */
int ldbm_initialize( void )
{
@ -194,7 +201,8 @@ int ldbm_shutdown( void )
return 0;
}
#endif
#endif /* ifdef HAVE_BERKELEY_DB */
#if defined( LDBM_USE_DBHASH ) || defined( LDBM_USE_DBBTREE )
@ -209,7 +217,7 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize )
{
LDBM ret = NULL;
#if defined( HAVE_BERKELEY_DB3 )
#if DB_VERSION_MAJOR >= 3
int err;
LDBM_LOCK;
err = db_create( &ret, ldbm_Env, 0 );
@ -244,7 +252,7 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize )
return NULL;
}
#elif defined( HAVE_BERKELEY_DB2 )
#elif DB_VERSION_MAJOR >= 2
DB_INFO dbinfo;
memset( &dbinfo, 0, sizeof( dbinfo ));
@ -298,9 +306,9 @@ void
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 );
@ -323,7 +331,7 @@ ldbm_fetch( LDBM ldbm, Datum key )
int rc;
LDBM_LOCK;
#if defined( HAVE_BERKELEY_DB3 )
#if DB_VERSION_MAJOR >= 3
ldbm_datum_init( data );
data.flags = DB_DBT_MALLOC;
@ -331,7 +339,7 @@ ldbm_fetch( LDBM ldbm, Datum key )
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;
@ -361,7 +369,7 @@ ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
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 )
{
@ -375,7 +383,7 @@ ldbm_store( LDBM ldbm, Datum key, Datum data, int flags )
}
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
@ -397,10 +405,10 @@ ldbm_delete( LDBM ldbm, Datum key )
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
@ -418,7 +426,7 @@ ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch )
{
Datum key, data;
#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
#if DB_VERSION_MAJOR >= 2
LDBMCursor *dbci;
ldbm_datum_init( key );
@ -429,7 +437,7 @@ ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch )
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)
@ -462,7 +470,7 @@ ldbm_firstkey( LDBM ldbm, LDBMCursor **dbch )
key.dsize = 0;
}
#if defined( HAVE_BERKELEY_DB2 ) || defined( HAVE_BERKELEY_DB3 )
#if DB_VERSION_MAJOR >= 2
}
#endif
@ -476,7 +484,7 @@ ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
{
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 );