From: Kurt Zeilenga Date: Fri, 22 Jan 1999 04:33:29 +0000 (+0000) Subject: Move libldap/strdup.c to string.c. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~716 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ddb0752b8f2a3e141467ef484d532d8f79b8879b;p=openldap Move libldap/strdup.c to string.c. libldap/string.c will hold various string.h replacements. Removed liblutil/strdup.c Moved ldap_pvt_strtok to string.c. Moved prototype of ldap_pvt_strtok to . Added #define strtok_r ldap_pvt_strtok (if strtok_r doesn't exist). --- diff --git a/configure b/configure index 60968bd1a6..7ca2ef8090 100755 --- a/configure +++ b/configure @@ -3593,8 +3593,8 @@ fi if test $ol_link_threads = no ; then - echo $ac_n "checking for pthread_create with -pthread""... $ac_c" 1>&6 -echo "configure:3598: checking for pthread_create with -pthread" >&5 + echo $ac_n "checking for pthread_create with -kthread""... $ac_c" 1>&6 +echo "configure:3598: checking for pthread_create with -kthread" >&5 if eval "test \"`echo '$''{'ol_cv_kthread_flag'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -8419,6 +8419,7 @@ for ac_func in \ sigset \ snprintf \ socket \ + strdup \ strerror \ strpbrk \ strrchr \ @@ -8433,12 +8434,12 @@ for ac_func in \ do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:8437: checking for $ac_func" >&5 +echo "configure:8438: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:8466: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -8495,12 +8496,12 @@ for ac_func in \ do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:8499: checking for $ac_func" >&5 +echo "configure:8500: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:8528: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -8548,20 +8549,21 @@ fi done -echo $ac_n "checking number of arguments of ctime_r""... $ac_c" 1>&6 -echo "configure:8553: checking number of arguments of ctime_r" >&5 +if test "$ac_cv_func_ctime_r" = yes ; then + echo $ac_n "checking number of arguments of ctime_r""... $ac_c" 1>&6 +echo "configure:8555: checking number of arguments of ctime_r" >&5 if eval "test \"`echo '$''{'ol_cv_func_ctime_r_nargs'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { time_t ti; char *buffer; ctime_r(&ti,buffer,32); ; return 0; } EOF -if { (eval echo configure:8565: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:8567: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ol_cv_func_ctime_r_nargs=3 else @@ -8573,7 +8575,7 @@ fi rm -f conftest* if test $ol_cv_func_ctime_r_nargs = 0 ; then cat > conftest.$ac_ext < int main() { @@ -8581,7 +8583,7 @@ time_t ti; char *buffer; ctime_r(&ti,buffer); ; return 0; } EOF -if { (eval echo configure:8585: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:8587: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ol_cv_func_ctime_r_nargs=2 else @@ -8603,12 +8605,15 @@ EOF fi +else + ol_cv_func_ctime_r=0 +fi -if test $ac_cv_func_strtok_r = yes \ - -a $ac_cv_func_ctime_r = yes \ - -a $ol_cv_func_ctime_r_nargs -ge 2 -a $ol_cv_func_ctime_r_nargs -le 3 \ - -a $ac_cv_func_gethostbyaddr_r = yes \ - -a $ac_cv_func_gethostbyname_r = yes \ +if test "$ac_cv_func_strtok_r" = yes \ + -a "$ac_cv_func_ctime_r" = yes \ + -a "$ol_cv_func_ctime_r_nargs" -ge 2 -a "$ol_cv_func_ctime_r_nargs" -le 3 \ + -a "$ac_cv_func_gethostbyaddr_r" = yes \ + -a "$ac_cv_func_gethostbyname_r" = yes \ ; then cat >> confdefs.h <<\EOF @@ -8624,15 +8629,15 @@ EOF fi -for ac_func in getopt strdup tempnam +for ac_func in getopt tempnam do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:8631: checking for $ac_func" >&5 +echo "configure:8636: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:8664: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -8685,13 +8690,13 @@ done # Check Configuration echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6 -echo "configure:8689: checking declaration of sys_errlist" >&5 +echo "configure:8694: checking declaration of sys_errlist" >&5 if eval "test \"`echo '$''{'ol_cv_dcl_sys_errlist'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -8701,7 +8706,7 @@ int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:8705: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:8710: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ol_cv_dcl_sys_errlist=yes else @@ -8722,20 +8727,20 @@ if test $ol_cv_dcl_sys_errlist = no ; then EOF echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6 -echo "configure:8726: checking existence of sys_errlist" >&5 +echo "configure:8731: checking existence of sys_errlist" >&5 if eval "test \"`echo '$''{'ol_cv_have_sys_errlist'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:8739: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:8744: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* ol_cv_have_sys_errlist=yes else diff --git a/configure.in b/configure.in index e1ac843819..d1dad6f652 100644 --- a/configure.in +++ b/configure.in @@ -1298,6 +1298,7 @@ AC_CHECK_FUNCS( \ sigset \ snprintf \ socket \ + strdup \ strerror \ strpbrk \ strrchr \ @@ -1319,13 +1320,17 @@ AC_CHECK_FUNCS( \ gethostbyname_r \ ) -OL_FUNC_CTIME_R_NARGS +if test "$ac_cv_func_ctime_r" = yes ; then + OL_FUNC_CTIME_R_NARGS +else + ol_cv_func_ctime_r=0 +fi -if test $ac_cv_func_strtok_r = yes \ - -a $ac_cv_func_ctime_r = yes \ - -a $ol_cv_func_ctime_r_nargs -ge 2 -a $ol_cv_func_ctime_r_nargs -le 3 \ - -a $ac_cv_func_gethostbyaddr_r = yes \ - -a $ac_cv_func_gethostbyname_r = yes \ +if test "$ac_cv_func_strtok_r" = yes \ + -a "$ac_cv_func_ctime_r" = yes \ + -a "$ol_cv_func_ctime_r_nargs" -ge 2 -a "$ol_cv_func_ctime_r_nargs" -le 3 \ + -a "$ac_cv_func_gethostbyaddr_r" = yes \ + -a "$ac_cv_func_gethostbyname_r" = yes \ ; then AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_REENTRANT, 1) @@ -1336,7 +1341,7 @@ if test $ol_link_threads != no ; then fi dnl We actually may need to replace more than this. -AC_REPLACE_FUNCS(getopt strdup tempnam) +AC_REPLACE_FUNCS(getopt tempnam) dnl ---------------------------------------------------------------- # Check Configuration diff --git a/include/ac/string.h b/include/ac/string.h index 8cf7bf0e04..2882db1240 100644 --- a/include/ac/string.h +++ b/include/ac/string.h @@ -42,10 +42,15 @@ # endif #endif +extern char *ldap_pvt_strtok( char *str, const char *delim, char **pos ); +#ifndef HAVE_STRTOK_R +# define strtok_r(s, d, p) ldap_pvt_strtok((s),(d),(p)) +#endif + +extern char *ldap_pvt_strdup( const char * s ); #ifndef HAVE_STRDUP /* strdup() is missing, declare our own version */ - extern char *ldap_pvt_strdup( const char * s ); -# define strdup ldap_pvt_strdup +# define strdup(s) ldap_pvt_strdup(s) #else /* some systems fail to declare strdup */ extern char *strdup(); diff --git a/include/ldap_pvt.h b/include/ldap_pvt.h index f7ee989119..6d42525b34 100644 --- a/include/ldap_pvt.h +++ b/include/ldap_pvt.h @@ -17,7 +17,6 @@ struct hostent; /* avoid pulling in */ -extern char *ldap_pvt_strtok( char *str, const char *delim, char **pos ); extern char *ldap_pvt_ctime( const time_t *tp, char *buf ); extern int ldap_pvt_gethostbyname_a( const char *name, diff --git a/libraries/libldap/Makefile.in b/libraries/libldap/Makefile.in index c1ae6a27af..25c1d518bd 100644 --- a/libraries/libldap/Makefile.in +++ b/libraries/libldap/Makefile.in @@ -15,7 +15,7 @@ SRCS = bind.c open.c result.c error.c compare.c search.c \ free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \ getdn.c getentry.c getattr.c getvalues.c addentry.c \ request.c getdxbyname.c os-ip.c url.c charset.c \ - init.c options.c strdup.c util-int.c + init.c options.c string.c util-int.c OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ controls.lo messages.lo references.lo \ modify.lo add.lo modrdn.lo delete.lo abandon.lo ufn.lo cache.lo \ @@ -23,7 +23,7 @@ OBJS = bind.lo open.lo result.lo error.lo compare.lo search.lo \ free.lo disptmpl.lo srchpref.lo dsparse.lo tmplout.lo sort.lo \ getdn.lo getentry.lo getattr.lo getvalues.lo addentry.lo \ request.lo getdxbyname.lo os-ip.lo url.lo charset.lo \ - init.lo options.lo strdup.lo util-int.lo + init.lo options.lo string.lo util-int.lo LDAP_INCDIR= ../../include LDAP_LIBDIR= ../../libraries diff --git a/libraries/libldap/strdup.c b/libraries/libldap/strdup.c deleted file mode 100644 index a251a660cc..0000000000 --- a/libraries/libldap/strdup.c +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ - -#include "portable.h" - -#include -#include -#include - -#include "ldap-int.h" - -char * -(ldap_pvt_strdup)( const char *s ) -{ - char *p; - int len; - len = strlen( s ) + 1; - if ( (p = (char *) malloc( len )) == NULL ) - return( (char *)0 ); - - memcpy( p, s, len ); - - return( p ); -} diff --git a/libraries/libldap/util-int.c b/libraries/libldap/util-int.c index e2b36c5f12..54d9d814e8 100644 --- a/libraries/libldap/util-int.c +++ b/libraries/libldap/util-int.c @@ -57,71 +57,6 @@ static ldap_pvt_thread_mutex_t ldap_int_gethostbyaddr_mutex; #undef HAVE_REENTRANT_FUNCTIONS #endif -#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_ctime( const time_t *tp, char *buf ) { #if (defined( HAVE_CTIME_R ) || defined( HAVE_REENTRANT_FUNCTIONS)) \ diff --git a/libraries/libldap_r/Makefile.in b/libraries/libldap_r/Makefile.in index 1713c05071..7a6cd137ec 100644 --- a/libraries/libldap_r/Makefile.in +++ b/libraries/libldap_r/Makefile.in @@ -14,7 +14,7 @@ XXSRCS = apitest.c test.c tmpltest.c \ free.c disptmpl.c srchpref.c dsparse.c tmplout.c sort.c \ getdn.c getentry.c getattr.c getvalues.c addentry.c \ request.c getdxbyname.c os-ip.c url.c charset.c \ - init.c options.c strdup.c util-int.c + init.c options.c string.c util-int.c SRCS = thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \ thr_stub.c rdwr.c OBJS = bind.lo controls.lo open.lo result.lo error.lo compare.lo search.lo \ @@ -23,7 +23,7 @@ OBJS = bind.lo controls.lo open.lo result.lo error.lo compare.lo search.lo \ free.lo disptmpl.lo srchpref.lo dsparse.lo tmplout.lo sort.lo \ getdn.lo getentry.lo getattr.lo getvalues.lo addentry.lo \ request.lo getdxbyname.lo os-ip.lo url.lo charset.lo \ - init.lo options.lo strdup.lo util-int.lo \ + init.lo options.lo string.lo util-int.lo \ thr_posix.lo thr_cthreads.lo thr_thr.lo thr_lwp.lo thr_nt.lo \ thr_stub.lo rdwr.lo diff --git a/libraries/liblutil/strdup.c b/libraries/liblutil/strdup.c deleted file mode 100644 index 27b0d81d54..0000000000 --- a/libraries/liblutil/strdup.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "portable.h" - -#ifndef HAVE_STRDUP - -#include -#include -#include "lutil.h" - -char *(strdup)( const char *s ) -{ - char *p; - - if ( (p = (char *) malloc( strlen( s ) + 1 )) == NULL ) - return( (char *)0 ); - - strcpy( p, s ); - - return( p ); -} - -#endif /* !strdup */