};
/* Pattern at top of allocated space */
-#define BER_MEM_JUNK 0xdeaddadaU
+#define LLBER_MEM_JUNK 0xdeaddadaU
-static const struct ber_mem_hdr ber_int_mem_hdr = { BER_MEM_JUNK, 0, 0 };
+static const struct ber_mem_hdr ber_int_mem_hdr = { LBER_MEM_JUNK, 0, 0 };
/* Note sequence and ber_int_options.lbu_meminuse are counters, but are not
* thread safe. If you want to use these values for multithreaded applications,
#ifdef LDAP_MEMORY_DEBUG
struct ber_mem_hdr *mh = (struct ber_mem_hdr *)
((char *)p - sizeof(struct ber_mem_hdr));
- assert( mh->bm_top == BER_MEM_JUNK);
+ assert( mh->bm_top == LBER_MEM_JUNK);
assert( testdatatop( mh));
assert( testend( (char *)&mh[1] + mh->bm_length) );
ber_int_options.lbo_meminuse -= mh->bm_length;
struct ber_mem_hdr *mh = malloc(s + sizeof(struct ber_mem_hdr) + sizeof( ber_int_t));
if( mh == NULL ) return NULL;
- mh->bm_top = BER_MEM_JUNK;
+ mh->bm_top = LBER_MEM_JUNK;
mh->bm_length = s;
setdatatop( mh);
setend( (char *)&mh[1] + mh->bm_length );
(n * s) + sizeof(struct ber_mem_hdr) + sizeof(ber_int_t) );
if( mh == NULL ) return NULL;
- mh->bm_top = BER_MEM_JUNK;
+ mh->bm_top = LBER_MEM_JUNK;
mh->bm_length = n*s;
setdatatop( mh);
setend( (char *)&mh[1] + mh->bm_length );
ber_int_t oldlen;
struct ber_mem_hdr *mh = (struct ber_mem_hdr *)
((char *)p - sizeof(struct ber_mem_hdr));
- assert( mh->bm_top == BER_MEM_JUNK);
+ assert( mh->bm_top == LBER_MEM_JUNK);
assert( testdatatop( mh));
assert( testend( (char *)&mh[1] + mh->bm_length) );
oldlen = mh->bm_length;
memset( (char *)&mh[1] + oldlen, 0xff, s - oldlen);
}
- assert( mh->bm_top == BER_MEM_JUNK);
+ assert( mh->bm_top == LBER_MEM_JUNK);
assert( testdatatop( mh));
ber_int_options.lbo_meminuse += s - oldlen;
ber_int_options.lbo_valid = LBER_INITIALIZED;
- if( bvec == NULL ) {
+ if( *bvec == NULL ) {
if( bv == NULL ) {
/* nothing to add */
return 0;
BER_MEM_VALID( bvec );
/* count entries */
- for ( i = 0; bvec[i] != NULL; i++ ) {
+ for ( i = 0; (*bvec)[i] != NULL; i++ ) {
/* EMPTY */;
}
AC_MEMCPY( p, s, len );
return p;
}
+
+char *
+ber_strndup( LDAP_CONST char *s, ber_len_t l )
+{
+ char *p;
+ size_t len;
+
+ ber_int_options.lbo_valid = LBER_INITIALIZED;
+
+#ifdef LDAP_MEMORY_DEBUG
+ assert(s != NULL); /* bv damn better point to something */
+#endif
+
+ if( s == NULL ) {
+ ber_errno = LBER_ERROR_PARAM;
+ return NULL;
+ }
+
+ len = strlen( s );
+
+ if ( len > l ) {
+ len = l;
+ }
+
+ if ( (p = LBER_MALLOC( len + 1 )) == NULL ) {
+ ber_errno = LBER_ERROR_MEMORY;
+ return NULL;
+ }
+
+ AC_MEMCPY( p, s, len );
+ p[ len ] = '\0';
+ return p;
+}
+
+char *
+ber_strndup__( LDAP_CONST char *s, size_t l )
+{
+ char *p;
+ size_t len;
+
+ if ( s == NULL ) {
+ return NULL;
+ }
+
+ len = strlen( s );
+ if (( p = LBER_MALLOC( len + 1 ) ) == NULL ) {
+ return NULL;
+ }
+
+ AC_MEMCPY( p, s, len );
+ p[ len ] = '\0';
+ return p;
+}