#include "ldap-int.h"
-#if defined( LDAP_R_COMPILE )
-# include <ldap_pvt_thread.h>
-#else
+#ifndef LDAP_R_COMPILE
# undef HAVE_REENTRANT_FUNCTIONS
-#endif
+# undef HAVE_CTIME_R
+# undef HAVE_GETHOSTBYNAME_R
+# undef HAVE_GETHOSTBYADDR_R
+
+#else
+# include <ldap_pvt_thread.h>
+ ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
#if (defined( HAVE_CTIME_R ) || defined( HAVE_REENTRANT_FUNCTIONS)) \
&& defined( CTIME_R_NARGS )
-# define USE_CTIME_R
-#endif
+# define USE_CTIME_R
+# else
+ static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
+# endif
-#if defined(HAVE_GETHOSTBYNAME_R) && \
- (GETHOSTBYNAME_R_NARGS > 6 || GETHOSTBYNAME_R_NARGS < 5)
+# if defined(HAVE_GETHOSTBYNAME_R) && \
+ (GETHOSTBYNAME_R_NARGS < 5) || (6 < GETHOSTBYNAME_R_NARGS)
/* Don't know how to handle this version, pretend it's not there */
# undef HAVE_GETHOSTBYNAME_R
-#endif
-#if defined(HAVE_GETHOSTBYADDR_R) && \
- (GETHOSTBYADDR_R_NARGS > 8 || GETHOSTBYADDR_R_NARGS < 7)
+# endif
+# if defined(HAVE_GETHOSTBYADDR_R) && \
+ (GETHOSTBYADDR_R_NARGS < 7) || (8 < GETHOSTBYADDR_R_NARGS)
/* Don't know how to handle this version, pretend it's not there */
# undef HAVE_GETHOSTBYADDR_R
-#endif
-
-#ifdef LDAP_R_COMPILE
-# ifndef USE_CTIME_R
- static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
-# endif
-# ifdef HAVE_RES_QUERY
- ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
# endif
#endif /* LDAP_R_COMPILE */
# endif
#else
+
# ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_lock( &ldap_int_ctime_mutex );
# endif
+
AC_MEMCPY( buf, ctime(tp), 26 );
+
# ifdef LDAP_R_COMPILE
ldap_pvt_thread_mutex_unlock( &ldap_int_ctime_mutex );
# endif
+
return buf;
#endif
}
static char *safe_realloc( char **buf, int len );
#if !defined(HAVE_GETHOSTBYNAME_R) && defined(LDAP_R_COMPILE)
-static int copy_hostent( struct hostent *res, char **buf, struct hostent * src );
+static int copy_hostent( struct hostent *res,
+ char **buf, struct hostent * src );
#endif
int ldap_pvt_gethostbyname_a(
return r;
#if (GETHOSTBYNAME_R_NARGS < 6)
- r = ((*result=gethostbyname_r( name, resbuf, *buf,
- buflen, herrno_ptr ))== NULL) ?
- -1 : 0;
+ *result=gethostbyname_r( name, resbuf, *buf, buflen, herrno_ptr );
+ r = (*result == NULL) ? -1 : 0;
#else
r = gethostbyname_r( name, resbuf, *buf,
buflen, result, herrno_ptr );
if (safe_realloc( buf, buflen )==NULL)
return r;
#if (GETHOSTBYADDR_R_NARGS < 8)
- r = ((*result=gethostbyaddr_r( addr, len, type,
- resbuf, *buf, buflen,
- herrno_ptr )) == NULL) ?
- -1 : 0;
+ *result=gethostbyaddr_r( addr, len, type,
+ resbuf, *buf, buflen, herrno_ptr );
+ r = (*result == NULL) ? -1 : 0;
#else
r = gethostbyaddr_r( addr, len, type,
resbuf, *buf, buflen,
ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
- return retval;
+ return retval;
+
#else /* gethostbyaddr() */
*buf = NULL;
*result = gethostbyaddr( addr, len, type );
done=1;
#ifdef LDAP_R_COMPILE
-
#if !defined( USE_CTIME_R ) && !defined( HAVE_REENTRANT_FUNCTIONS )
ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
#endif
-
-#ifdef HAVE_RES_QUERY
ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
#endif
/* call other module init functions here... */
-#endif
}
#if defined( NEED_COPY_HOSTENT )
# undef NEED_SAFE_REALLOC
#define NEED_SAFE_REALLOC
-static char *cpy_aliases( char ***tgtio, char *buf, char **src )
+static char *cpy_aliases(
+ char ***tgtio,
+ char *buf,
+ char **src )
{
int len;
char **tgt=*tgtio;
return buf;
}
-static char *cpy_addresses( char ***tgtio, char *buf, char **src, int len )
+static char *cpy_addresses(
+ char ***tgtio,
+ char *buf,
+ char **src,
+ int len )
{
char **tgt=*tgtio;
for( ; (*src) ; src++ ) {
return buf;
}
-static int copy_hostent( struct hostent *res, char **buf, struct hostent * src )
+static int copy_hostent(
+ struct hostent *res,
+ char **buf,
+ struct hostent * src )
{
char **p;
char **tp;