From: Kurt Zeilenga Date: Sun, 24 Jan 1999 01:32:04 +0000 (+0000) Subject: Forgotten commit of string rearrangement. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~705 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=941087a09dcec4d5d68c3fca0a77dca1a203436b;p=openldap Forgotten commit of string rearrangement. --- diff --git a/libraries/libldap/string.c b/libraries/libldap/string.c index a251a660cc..a0877bb683 100644 --- a/libraries/libldap/string.c +++ b/libraries/libldap/string.c @@ -11,16 +11,99 @@ #include "ldap-int.h" + +#if defined ( HAVE_STRSPN ) +#define int_strspn strspn +#else +static int int_strspn( const char *str, const char *delim ) +{ + 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 + +#if defined( HAVE_STRPBRK ) +#define int_strpbrk strpbrk +#else +static char *(int_strpbrk)( const char *str, const char *accept ) +{ + const char *p; + + for( ; (*str) ; str++ ) { + for( p=accept; (*p) ; p++) { + if (*str==*p) { + return str; + } + } + } + + return NULL; +} +#endif + +char *(ldap_pvt_strtok)( char *str, const char *delim, char **pos ) +{ +#if defined( HAVE_STRTOK_R ) || defined( HAVE_REENTRANT_FUNCTIONS ) + return strtok_r(str, delim, pos); +#else + 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 +} + char * (ldap_pvt_strdup)( const char *s ) { - char *p; - int len; - len = strlen( s ) + 1; - if ( (p = (char *) malloc( len )) == NULL ) - return( (char *)0 ); + char *p; + int len = strlen( s ) + 1; - memcpy( p, s, len ); + if ( (p = (char *) malloc( len )) == NULL ) { + return( (char *)0 ); + } - return( p ); + memcpy( p, s, len ); + return( p ); }