From 114a0cd339c9a1b7dfe62b474ea0b9cb6f00826e Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Sat, 2 Jan 1999 23:40:31 +0000 Subject: [PATCH] Update ctime_r() argument macro to cache results and to produce one preprocessor macro instead of two. Ran aclocal, autoconf, autoheader to update derived files. Modify util-int.c to use CTIME_R_NARGS define and fallback to ctime() if not set. Made LDAP_API_FEATURE_X_OPENLDAP_REENTRANT dependent upon result. --- acconfig.h | 3 ++ aclocal.m4 | 27 +------------ build/openldap.m4 | 31 +++++++-------- configure | 75 +++++++++++++++++++++++++++++++----- configure.in | 5 ++- include/portable.h.in | 9 ++--- libraries/libldap/util-int.c | 10 ++--- 7 files changed, 96 insertions(+), 64 deletions(-) diff --git a/acconfig.h b/acconfig.h index a4a0fe94d0..7280eef913 100644 --- a/acconfig.h +++ b/acconfig.h @@ -25,6 +25,9 @@ /* define this if toupper() requires tolower() check */ #undef C_UPPER_LOWER +/* define this to the number of arguments ctime_r() expects +#undef CTIME_R_NARGS + /* define this if sys_errlist is not defined in stdio.h or errno.h */ #undef DECL_SYS_ERRLIST diff --git a/aclocal.m4 b/aclocal.m4 index bdb05477ee..65d59a0af8 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -10,6 +10,8 @@ dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A dnl PARTICULAR PURPOSE. +dnl Copyright 1998 The OpenLDAP Foundation, All Rights Reserved. +dnl COPYING RESTRICTIONS APPLY, See COPYRIGHT file dnl dnl OpenLDAP Autoconf Macros dnl @@ -506,28 +508,3 @@ AC_DEFUN(AM_TYPE_PTRDIFF_T, fi ]) -dnl check arguments for ctime_r - Bart Hartgers - -# serial 1 -AC_DEFUN(OL_NARGS_CTIME_R, - [AC_MSG_CHECKING([number of args for ctime_r]) - AC_TRY_COMPILE([#include ], - [time_t ti; char *buffer; - ctime_r(&ti,buffer,32);],ol_nargs_ctime_r=3, - ol_nargs_ctime_r=0) - if test $ol_nargs_ctime_r = 0 ; then - AC_TRY_COMPILE([#include ], - [time_t ti; char *buffer; - ctime_r(&ti,buffer);],ol_nargs_ctime_r=2 ) - fi - AC_MSG_RESULT($ol_nargs_ctime_r) - if test $ol_nargs_ctime_r = 2 ; then - AC_DEFINE( ARGS_CTIME_R_2 ) - fi - if test $ol_nargs_ctime_r = 3 ; then - AC_DEFINE( ARGS_CTIME_R_3 ) - fi -]) - - - diff --git a/build/openldap.m4 b/build/openldap.m4 index c72ab19a17..30b2873bd4 100644 --- a/build/openldap.m4 +++ b/build/openldap.m4 @@ -427,23 +427,20 @@ AC_DEFUN(OL_TYPE_SIG_ATOMIC_T, dnl ==================================================================== dnl check no of arguments for ctime_r -AC_DEFUN(OL_NARGS_CTIME_R, - [AC_MSG_CHECKING([number of args for ctime_r]) - AC_TRY_COMPILE([#include ], - [time_t ti; char *buffer; - ctime_r(&ti,buffer,32);],ol_nargs_ctime_r=3, - ol_nargs_ctime_r=0) - if test $ol_nargs_ctime_r = 0 ; then - AC_TRY_COMPILE([#include ], - [time_t ti; char *buffer; - ctime_r(&ti,buffer);],ol_nargs_ctime_r=2 ) - fi - AC_MSG_RESULT($ol_nargs_ctime_r) - if test $ol_nargs_ctime_r = 2 ; then - AC_DEFINE( ARGS_CTIME_R_2 ) - fi - if test $ol_nargs_ctime_r = 3 ; then - AC_DEFINE( ARGS_CTIME_R_3 ) +AC_DEFUN(OL_FUNC_CTIME_R_NARGS, + [AC_CACHE_CHECK(number of arguments of ctime_r, ol_cv_func_ctime_r_nargs, + [AC_TRY_COMPILE([#include ], + [time_t ti; char *buffer; ctime_r(&ti,buffer,32);], + ol_cv_func_ctime_r_nargs=3, ol_cv_func_ctime_r_nargs=0) + if test $ol_cv_func_ctime_r_nargs = 0 ; then + AC_TRY_COMPILE([#include ], + [time_t ti; char *buffer; + ctime_r(&ti,buffer);], + ol_cv_func_ctime_r_nargs=2, ol_cv_func_ctime_r_nargs=0) + fi + ]) + if test $ol_cv_func_ctime_r_nargs -gt 1 ; then + AC_DEFINE_UNQUOTED(CTIME_R_NARGS, $ol_cv_func_ctime_r_nargs) fi ])dnl diff --git a/configure b/configure index 8471490724..fc2d42b72c 100755 --- a/configure +++ b/configure @@ -8191,8 +8191,65 @@ fi done +echo $ac_n "checking number of arguments of ctime_r""... $ac_c" 1>&6 +echo "configure:8196: 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:8208: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ol_cv_func_ctime_r_nargs=3 +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ol_cv_func_ctime_r_nargs=0 +fi +rm -f conftest* + if test $ol_cv_func_ctime_r_nargs = 0 ; then + cat > conftest.$ac_ext < +int main() { +time_t ti; char *buffer; + ctime_r(&ti,buffer); +; return 0; } +EOF +if { (eval echo configure:8228: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ol_cv_func_ctime_r_nargs=2 +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ol_cv_func_ctime_r_nargs=0 +fi +rm -f conftest* + fi + +fi + +echo "$ac_t""$ol_cv_func_ctime_r_nargs" 1>&6 + if test $ol_cv_func_ctime_r_nargs -gt 1 ; then + cat >> confdefs.h <&6 -echo "configure:8217: checking for $ac_func" >&5 +echo "configure:8274: 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:8302: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -8271,13 +8328,13 @@ done # Check Configuration echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6 -echo "configure:8275: checking declaration of sys_errlist" >&5 +echo "configure:8332: 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 < @@ -8287,7 +8344,7 @@ int main() { char *c = (char *) *sys_errlist ; return 0; } EOF -if { (eval echo configure:8291: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:8348: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ol_cv_dcl_sys_errlist=yes else @@ -8308,20 +8365,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:8312: checking existence of sys_errlist" >&5 +echo "configure:8369: 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:8325: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then +if { (eval echo configure:8382: \"$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 955271f7be..febf88fe2f 100644 --- a/configure.in +++ b/configure.in @@ -1223,8 +1223,11 @@ AC_CHECK_FUNCS( \ gethostbyname_r \ ) +OL_FUNC_CTIME_R_NARGS + 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 @@ -1232,8 +1235,6 @@ if test $ac_cv_func_strtok_r = yes \ AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_REENTRANT, 1) fi -OL_NARGS_CTIME_R - if test $ol_link_threads != no ; then AC_DEFINE(LDAP_API_FEATURE_X_OPENLDAP_THREAD_SAFE, 1) fi diff --git a/include/portable.h.in b/include/portable.h.in index a4a67bd71a..b35f13612b 100644 --- a/include/portable.h.in +++ b/include/portable.h.in @@ -107,6 +107,9 @@ /* define this if toupper() requires tolower() check */ #undef C_UPPER_LOWER +/* define this to the number of arguments ctime_r() expects +#undef CTIME_R_NARGS + /* define this if sys_errlist is not defined in stdio.h or errno.h */ #undef DECL_SYS_ERRLIST @@ -274,12 +277,6 @@ /* Define if you have the ctime_r function. */ #undef HAVE_CTIME_R -/* Define if ctime_r takes two arguments */ -#undef ARGS_CTIME_R_2 - -/* Define if ctime_r takes three arguments */ -#undef ARGS_CTIME_R_3 - /* Define if you have the flock function. */ #undef HAVE_FLOCK diff --git a/libraries/libldap/util-int.c b/libraries/libldap/util-int.c index 3ace0c799b..31cbaafbe3 100644 --- a/libraries/libldap/util-int.c +++ b/libraries/libldap/util-int.c @@ -41,13 +41,13 @@ char *ldap_int_strtok( char *str, const char *delim, char **pos ) char *ldap_int_ctime( const time_t *tp, char *buf ) { -#ifdef HAVE_CTIME_R -# if defined( ARGS_CTIME_R_2 ) - return ctime_r(tp,buf); -# elif defined( ARGS_CTIME_R_3 ) +#if defined( HAVE_CTIME_R ) && defined( CTIME_R_NARGS ) +# if (CTIME_R_NARGS > 3) || (CTIME_R_NARGS < 2) + choke me! nargs should have 2 or 3 +# elif CTIME_R_NARGS > 2 return ctime_r(tp,buf,26); # else - Do not know how many arguments ctime_r takes, so generating error + return ctime_r(tp,buf); # endif #else return ctime(tp); -- 2.39.5