define and use ber_strnlen() (ITS#6080); please regenerate configure and include/portable.hin

This commit is contained in:
Pierangelo Masarati 2009-04-29 11:38:31 +00:00
parent 477e602afd
commit 85b47ab0e7
3 changed files with 28 additions and 5 deletions

View file

@ -2480,6 +2480,7 @@ AC_CHECK_FUNCS( \
seteuid \
signal \
strdup \
strnlen \
strpbrk \
strrchr \
strsep \

View file

@ -629,6 +629,14 @@ LBER_F( char * )
ber_strdup LDAP_P((
LDAP_CONST char * ));
LBER_F( ber_len_t )
ber_strnlen LDAP_P((
LDAP_CONST char *s, ber_len_t len ));
LBER_F( char * )
ber_strndup LDAP_P((
LDAP_CONST char *s, ber_len_t l ));
LBER_F( struct berval * )
ber_bvreplace LDAP_P((
struct berval *dst, LDAP_CONST struct berval *src ));

View file

@ -651,6 +651,24 @@ ber_strdup( LDAP_CONST char *s )
return ber_strdup_x( s, NULL );
}
ber_len_t
ber_strnlen( LDAP_CONST char *s, ber_len_t len )
{
#ifdef HAVE_STRNLEN
return (ber_len_t)strnlen( s, (ber_len_t)len );
#else
ber_len_t l;
for ( l = 0; l < len; l++ ) {
if ( s[l] == '\0' ) {
return l;
}
}
return len;
#endif /* HAVE_STRNLEN */
}
char *
ber_strndup_x( LDAP_CONST char *s, ber_len_t l, void *ctx )
{
@ -666,11 +684,7 @@ ber_strndup_x( LDAP_CONST char *s, ber_len_t l, void *ctx )
return NULL;
}
len = strlen( s );
if ( len > l ) {
len = l;
}
len = ber_strnlen( s, l );
if ( (p = ber_memalloc_x( len + 1, ctx )) == NULL ) {
ber_errno = LBER_ERROR_MEMORY;