From: Bart Hartgers Date: Thu, 14 Jan 1999 15:19:29 +0000 (+0000) Subject: Improved ldap_int_strtok. If strtok_r does not exists, it will be worked X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~780 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f6a47058b65c36c1cf06331cc672c735eae2bd62;p=openldap Improved ldap_int_strtok. If strtok_r does not exists, it will be worked simulated with strspn and strpbrk. If strspn or strpbrk aren't there, they will be supplied. In addition, the memory-handling of the ldap_int_gethostby's is better now. --- diff --git a/configure.in b/configure.in index 4ac5322d92..afd909097e 100644 --- a/configure.in +++ b/configure.in @@ -1254,6 +1254,8 @@ AC_CHECK_FUNCS( \ strtok \ strtol \ strtoul \ + strspn \ + strpbrk \ sysconf \ waitpid \ ) diff --git a/libraries/libldap/util-int.c b/libraries/libldap/util-int.c index 31cbaafbe3..2eb4a8c23a 100644 --- a/libraries/libldap/util-int.c +++ b/libraries/libldap/util-int.c @@ -30,12 +30,68 @@ #include "ldap-int.h" +static int int_strspn( const char *str, const char *delim ) +{ +#if defined( HAVE_STRSPN ) + return strspn( str, delim ); +#else + int pos; + const char *p=delim; + for( pos=0; (*str) ; pos++,str++) { + if (*str!=*p) + for( p=delim; (*p) ; p++ ) { + if (*str==*p) + break; + } + if (*p=='\0') + return pos; + } + return pos; +#endif +} + +static char *int_strpbrk( const char *str, const char *accept ) +{ +#if defined( HAVE_STRPBRK ) + return strpbrk( str, accept ); +#else + const char *p; + for( ; (*str) ; str++ ) { + for( p=accept; (*p) ; p++) { + if (*str==*p) + return str; + } + } + return NULL; +#endif +} + char *ldap_int_strtok( char *str, const char *delim, char **pos ) { #ifdef HAVE_STRTOK_R return strtok_r(str, delim, pos); #else - return strtok(str, delim); + char *p; + + if (pos==NULL) + return NULL; + if (str==NULL) { + if (*pos==NULL) + return NULL; + str=*pos; + } + /* skip any initial delimiters */ + str += int_strspn( str, delim ); + if (*str == '\0') + return NULL; + p = int_strpbrk( str, delim ); + if (p==NULL) { + *pos = NULL; + } else { + *p ='\0'; + *pos = p+1; + } + return str; #endif } @@ -50,7 +106,8 @@ char *ldap_int_ctime( const time_t *tp, char *buf ) return ctime_r(tp,buf); # endif #else - return ctime(tp); + memcpy( buf, ctime(tp), 26 ); + return buf; #endif } @@ -66,7 +123,7 @@ static char *safe_realloc( char **buf, int len ) } return tmpbuf; } - + int ldap_int_gethostbyname_a( const char *name, struct hostent *resbuf, @@ -75,28 +132,27 @@ int ldap_int_gethostbyname_a( int *herrno_ptr ) { #ifdef HAVE_GETHOSTBYNAME_R - int r; + int r=-1; int buflen=BUFSTART; - - if (safe_realloc( buf, buflen)) { - for(;buflen