]> git.sur5r.net Git - openldap/commitdiff
don't leave dependencies on liblutil in libldap :)
authorPierangelo Masarati <ando@openldap.org>
Sun, 17 Dec 2006 22:04:25 +0000 (22:04 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 17 Dec 2006 22:04:25 +0000 (22:04 +0000)
include/lutil.h
libraries/libldap/abandon.c
libraries/libldap/ldap-int.h
libraries/libldap/result.c
libraries/liblutil/utils.c

index 7162c4bf9de7f5d89767d9fa01c8d45d37828250..b4d0108e6b59f8b4437fbd6daa4e7a016dc0fb6e 100644 (file)
@@ -322,13 +322,6 @@ lutil_unparse_time( char *buf, size_t buflen, unsigned long t );
        } while ( 0 );
 #endif /* ! timermul */
 
-LDAP_LUTIL_F (int)
-lutil_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp );
-LDAP_LUTIL_F (int)
-lutil_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx );
-LDAP_LUTIL_F (int)
-lutil_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx );
-
 LDAP_END_DECL
 
 #endif /* _LUTIL_H */
index 9785b21b161499073c072b1194c3a00da32caf5d..568c073868aeaf1d441f4382c8238aaabfdfabc4 100644 (file)
@@ -311,9 +311,9 @@ start_again:;
        /* use bisection */
        i = 0;
        if ( ld->ld_nabandoned == 0 ||
-               lutil_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, &i ) == 0 )
+               ldap_int_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, &i ) == 0 )
        {
-               lutil_bisect_insert( &ld->ld_abandoned, &ld->ld_nabandoned, msgid, i );
+               ldap_int_bisect_insert( &ld->ld_abandoned, &ld->ld_nabandoned, msgid, i );
        }
 
        if ( err != -1 ) {
@@ -326,3 +326,155 @@ start_again:;
 #endif
        return( ld->ld_errno );
 }
+
+/*
+ * ldap_int_bisect_find
+ *
+ * args:
+ *     v:      array of length n (in)
+ *     n:      length of array v (in)
+ *     id:     value to look for (in)
+ *     idxp:   pointer to location of value/insert point
+ *
+ * return:
+ *     0:      not found
+ *     1:      found
+ *     -1:     error
+ */
+int
+ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
+{
+       int             begin,
+                       end,
+                       i,
+                       rc = 0;
+
+       assert( n >= 0 );
+       assert( id >= 0 );
+
+       begin = 0;
+       end = n - 1;
+
+       if ( n > 0 ) {
+               if ( id < v[ begin ] ) {
+                       *idxp = 0;
+
+               } else if ( id > v[ end ] ) {
+                       *idxp = n;
+
+               } else {
+                       int             pos;
+                       ber_int_t       curid;
+       
+                       while ( end >= begin ) {
+                               pos = (begin + end)/2;
+                               curid = v[ pos ];
+       
+                               if ( id < curid ) {
+                                       end = pos - 1;
+       
+                               } else if ( id > curid ) {
+                                       begin = pos + 1;
+       
+                               } else {
+                                       /* already abandoned? */
+                                       *idxp = pos;
+                                       rc = 1;
+                                       break;
+                               }
+                       }
+       
+                       if ( rc == 0 ) {
+                               *idxp = pos + ( id > curid ? 1 : 0 );
+                       }
+               }
+
+       } else {
+               *idxp = 0;
+       }
+
+       return rc;
+}
+
+/*
+ * ldap_int_bisect_insert
+ *
+ * args:
+ *     vp:     pointer to array of length *np (in/out)
+ *     np:     pointer to length of array *vp (in/out)
+ *     id:     value to insert (in)
+ *     idx:    location of insert point (as computed by ldap_int_bisect_find())
+ *
+ * return:
+ *     0:      inserted
+ *     -1:     error
+ */
+int
+ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx )
+{
+       ber_int_t       *v;
+       ber_len_t       n;
+       int             i;
+
+       assert( vp != NULL );
+       assert( np != NULL );
+       assert( *np >= 0 );
+       assert( idx >= 0 );
+       assert( idx <= *np );
+
+       n = *np;
+
+       v = ber_memrealloc( *vp, sizeof( ber_int_t ) * ( n + 1 ) );
+       if ( v == NULL ) {
+               return -1;
+       }
+       *vp = v;
+
+       for ( i = n; i > idx; i-- ) {
+               v[ i ] = v[ i - 1 ];
+       }
+       v[ idx ] = id;
+       ++(*np);
+
+       return 0;
+}
+
+/*
+ * ldap_int_bisect_delete
+ *
+ * args:
+ *     vp:     pointer to array of length *np (in/out)
+ *     np:     pointer to length of array *vp (in/out)
+ *     id:     value to delete (in)
+ *     idx:    location of value to delete (as computed by ldap_int_bisect_find())
+ *
+ * return:
+ *     0:      deleted
+ */
+int
+ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx )
+{
+       ber_int_t       *v;
+       ber_len_t       n;
+       int             i;
+
+       assert( vp != NULL );
+       assert( np != NULL );
+       assert( *np >= 0 );
+       assert( idx >= 0 );
+       assert( idx < *np );
+
+       v = *vp;
+
+       assert( v[ idx ] == id );
+
+       --(*np);
+       n = *np;
+
+       for ( i = idx; i < n; i++ ) {
+               v[ i ] = v[ i + 1 ];
+       }
+
+       return 0;
+}
+
index 9a19f29aa51db9f3e65b9bd22e8a9e839180add7..69473e0f85d78aa5b98cc21bc5820e0ca162c867 100644 (file)
@@ -398,6 +398,17 @@ LDAP_V( ldap_pvt_thread_mutex_t ) ldap_int_sasl_mutex;
 #define        LDAP_NEXT_MSGID(ld, id) id = ++(ld)->ld_msgid
 #endif
 
+/*
+ * in abandon.c
+ */
+
+LDAP_F (int)
+ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp );
+LDAP_F (int)
+ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx );
+LDAP_F (int)
+ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx );
+
 /*
  * in init.c
  */
index 9e594c017a95cd106c18a2d602fcf490d1a98bcd..34cb90e11ae43fbadde1845f5518a58a0ce7b7dd 100644 (file)
@@ -1237,7 +1237,7 @@ ldap_abandoned( LDAP *ld, ber_int_t msgid, int *idxp )
        assert( msgid >= 0 );
        assert( ld->ld_nabandoned >= 0 );
 
-       return lutil_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, idxp );
+       return ldap_int_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, idxp );
 }
 
 /*
@@ -1252,11 +1252,11 @@ ldap_mark_abandoned( LDAP *ld, ber_int_t msgid, int idx )
        LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex );
 #endif
 
-       /* NOTE: those assertions are repeated in lutil_bisect_delete() */
+       /* NOTE: those assertions are repeated in ldap_int_bisect_delete() */
        assert( idx >= 0 );
        assert( idx < ld->ld_nabandoned );
        assert( ld->ld_abandoned[ idx ] == msgid );
 
-       return lutil_bisect_delete( &ld->ld_abandoned, &ld->ld_nabandoned,
+       return ldap_int_bisect_delete( &ld->ld_abandoned, &ld->ld_nabandoned,
                msgid, idx );
 }
index bffeef84a4c3f1ad3e845fab4f719aba7b016471..94badf831e0b7e54c0a4c2147ed8cbd839958a90 100644 (file)
@@ -572,154 +572,3 @@ lutil_unparse_time(
        return 0;
 }
 
-/*
- * lutil_bisect_find
- *
- * args:
- *     v:      array of length n (in)
- *     n:      length of array v (in)
- *     id:     value to look for (in)
- *     idxp:   pointer to location of value/insert point
- *
- * return:
- *     0:      not found
- *     1:      found
- *     -1:     error
- */
-int
-lutil_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
-{
-       int             begin,
-                       end,
-                       i,
-                       rc = 0;
-
-       assert( n >= 0 );
-       assert( id >= 0 );
-
-       begin = 0;
-       end = n - 1;
-
-       if ( n > 0 ) {
-               if ( id < v[ begin ] ) {
-                       *idxp = 0;
-
-               } else if ( id > v[ end ] ) {
-                       *idxp = n;
-
-               } else {
-                       int             pos;
-                       ber_int_t       curid;
-       
-                       while ( end >= begin ) {
-                               pos = (begin + end)/2;
-                               curid = v[ pos ];
-       
-                               if ( id < curid ) {
-                                       end = pos - 1;
-       
-                               } else if ( id > curid ) {
-                                       begin = pos + 1;
-       
-                               } else {
-                                       /* already abandoned? */
-                                       *idxp = pos;
-                                       rc = 1;
-                                       break;
-                               }
-                       }
-       
-                       if ( rc == 0 ) {
-                               *idxp = pos + ( id > curid ? 1 : 0 );
-                       }
-               }
-
-       } else {
-               *idxp = 0;
-       }
-
-       return rc;
-}
-
-/*
- * lutil_bisect_insert
- *
- * args:
- *     vp:     pointer to array of length *np (in/out)
- *     np:     pointer to length of array *vp (in/out)
- *     id:     value to insert (in)
- *     idx:    location of insert point (as computed by lutil_bosect_find())
- *
- * return:
- *     0:      inserted
- *     -1:     error
- */
-int
-lutil_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx )
-{
-       ber_int_t       *v;
-       ber_len_t       n;
-       int             i;
-
-       assert( vp != NULL );
-       assert( np != NULL );
-       assert( *np >= 0 );
-       assert( idx >= 0 );
-       assert( idx <= *np );
-
-       n = *np;
-
-       v = ber_memrealloc( *vp, sizeof( ber_int_t ) * ( n + 1 ) );
-       if ( v == NULL ) {
-               return -1;
-       }
-       *vp = v;
-
-       for ( i = n; i > idx; i-- ) {
-               v[ i ] = v[ i - 1 ];
-       }
-       v[ idx ] = id;
-       ++(*np);
-
-       return 0;
-}
-
-/*
- * lutil_bisect_delete
- *
- * args:
- *     vp:     pointer to array of length *np (in/out)
- *     np:     pointer to length of array *vp (in/out)
- *     id:     value to delete (in)
- *     idx:    location of value to delete (as computed by lutil_bosect_find())
- *
- * return:
- *     0:      deleted
- */
-int
-lutil_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx )
-{
-       ber_int_t       *v;
-       ber_len_t       n;
-       int             i;
-
-       assert( vp != NULL );
-       assert( np != NULL );
-       assert( *np >= 0 );
-       assert( idx >= 0 );
-       assert( idx < *np );
-
-       v = *vp;
-
-       assert( v[ idx ] == id );
-
-       --(*np);
-       n = *np;
-
-       for ( i = idx; i < n; i++ ) {
-               v[ i ] = v[ i + 1 ];
-       }
-
-       return 0;
-}
-