/* $OpenLDAP$ */
/*
- * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
};
/* Pattern at top of allocated space */
-#define LLBER_MEM_JUNK 0xdeaddadaU
+#define LBER_MEM_JUNK 0xdeaddadaU
static const struct ber_mem_hdr ber_int_mem_hdr = { LBER_MEM_JUNK, 0, 0 };
return( new );
}
+struct berval *
+ber_mem2bv(
+ LDAP_CONST char *s, ber_len_t len, int dup, struct berval *bv)
+{
+ struct berval *new;
+
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
+ if( s == NULL ) {
+ ber_errno = LBER_ERROR_PARAM;
+ return NULL;
+ }
+
+ if( bv ) {
+ new = bv;
+ } else {
+ if(( new = LBER_MALLOC( sizeof(struct berval) )) == NULL ) {
+ ber_errno = LBER_ERROR_MEMORY;
+ return NULL;
+ }
+ }
+
+ new->bv_len = len;
+ if ( dup ) {
+ if ( (new->bv_val = LBER_MALLOC( new->bv_len+1 )) == NULL ) {
+ ber_errno = LBER_ERROR_MEMORY;
+ if ( !bv )
+ LBER_FREE( new );
+ return NULL;
+ }
+
+ AC_MEMCPY( new->bv_val, s, new->bv_len );
+ new->bv_val[new->bv_len] = '\0';
+ } else {
+ new->bv_val = (char *) s;
+ }
+
+ return( new );
+}
+
char *
ber_strdup( LDAP_CONST char *s )
{
return 0;
}
n = 0;
+
*a = (BerValue *) LBER_MALLOC( 2 * sizeof(BerValue) );
+ if ( *a == NULL ) {
+ return -1;
+ }
+
} else {
+ BerVarray atmp;
BER_MEM_VALID( a );
for ( n = 0; *a != NULL && (*a)[n].bv_val != NULL; n++ ) {
- ; /* NULL */
+ ; /* just count them */
}
if (bv == NULL) {
return n;
}
- *a = (BerValue *) LBER_REALLOC( (char *) *a,
+
+ atmp = (BerValue *) LBER_REALLOC( (char *) *a,
(n + 2) * sizeof(BerValue) );
- }
- if ( *a == NULL ) {
- return -1;
+
+ if( atmp == NULL ) {
+ return -1;
+ }
+
+ *a = atmp;
}
(*a)[n++] = *bv;
return n;
}
+