]> git.sur5r.net Git - openldap/commitdiff
ITS#450: teach LDBM/GDBM about cursors
authorKurt Zeilenga <kurt@openldap.org>
Fri, 11 Feb 2000 02:05:14 +0000 (02:05 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 11 Feb 2000 02:05:14 +0000 (02:05 +0000)
include/ldbm.h
libraries/libldbm/ldbm.c

index 145c8829688a4f7b844a08e1a90dafb4f04b7118..e7f0b10f98996702f7d621fe990dc19fa056369a 100644 (file)
@@ -66,7 +66,7 @@ typedef DBC   LDBMCursor;
 # endif
 
 #else
-typedef int LDBMCursor;
+typedef void LDBMCursor;
 #      define LDBM_READER      O_RDONLY
 #      define LDBM_WRITER      O_RDWR
 #      define LDBM_WRCREAT     (O_RDWR|O_CREAT)
@@ -107,7 +107,7 @@ LDAP_END_DECL
 LDAP_BEGIN_DECL
 
 typedef datum          Datum;
-typedef int LDBMCursor;
+typedef Datum LDBMCursor;
 typedef GDBM_FILE      LDBM;
 
 extern gdbm_error      gdbm_errno;
index 59305bb582aef4006421884932d230a5ec1c36f7..33592e7be65df92935d2756ece82997d1e16e53b 100644 (file)
@@ -529,6 +529,11 @@ ldbm_firstkey( LDBM ldbm, LDBMCursor **dbcp )
        d = gdbm_firstkey( ldbm );
        LDBM_UNLOCK;
 
+       if ( d.dptr != NULL ) {
+               *dbcp = (Datum *) malloc( sizeof( Datum ) );
+               **dbcp = ldbm_datum_dup( ldbm, d );
+       }
+
        return d;
 }
 
@@ -538,9 +543,17 @@ ldbm_nextkey( LDBM ldbm, Datum key, LDBMCursor *dbcp )
        Datum d;
 
        LDBM_LOCK;
-       d = gdbm_nextkey( ldbm, key );
+       d = gdbm_nextkey( ldbm, *dbcp );
        LDBM_UNLOCK;
 
+       ldbm_datum_free( ldbm, *dbcp );
+
+       if ( d.dptr != NULL ) {
+               *dbcp = ldbm_datum_dup( ldbm, d );
+       } else {
+               free( dbcp );
+       }
+
        return d;
 }