]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/util-int.c
Merge branch 'mdb.master' of ssh://git-master.openldap.org/~git/git/openldap
[openldap] / libraries / libldap / util-int.c
index d19f2b80695df047b1ec73765ba36a50275af33c..f0b5f72f04fe7950c8f7da7383b60aff8cdeaa0d 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2009 The OpenLDAP Foundation.
+ * Copyright 1998-2011 The OpenLDAP Foundation.
  * Portions Copyright 1998 A. Hartgers.
  * All rights reserved.
  *
@@ -68,12 +68,17 @@ extern int h_errno;
 
 /* USE_GMTIME_R and USE_LOCALTIME_R defined in ldap_pvt.h */
 
+#ifdef LDAP_DEVEL
+       /* to be released with 2.5 */
 #if !defined( USE_GMTIME_R ) || !defined( USE_LOCALTIME_R )
        /* we use the same mutex for gmtime(3) and localtime(3)
         * because implementations may use the same buffer
         * for both functions */
        static ldap_pvt_thread_mutex_t ldap_int_gmtime_mutex;
 #endif
+#else /* ! LDAP_DEVEL */
+       ldap_pvt_thread_mutex_t ldap_int_gmtime_mutex;
+#endif /* ! LDAP_DEVEL */
 
 # if defined(HAVE_GETHOSTBYNAME_R) && \
        (GETHOSTBYNAME_R_NARGS < 5) || (6 < GETHOSTBYNAME_R_NARGS)
@@ -102,15 +107,9 @@ char *ldap_pvt_ctime( const time_t *tp, char *buf )
 
 #else
 
-# ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_lock( &ldap_int_ctime_mutex );
-# endif
-
+       LDAP_MUTEX_LOCK( &ldap_int_ctime_mutex );
        AC_MEMCPY( buf, ctime(tp), 26 );
-
-# ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_unlock( &ldap_int_ctime_mutex );
-# endif
+       LDAP_MUTEX_UNLOCK( &ldap_int_ctime_mutex );
 
        return buf;
 #endif 
@@ -144,10 +143,7 @@ ldap_pvt_gmtime( const time_t *timep, struct tm *result )
 {
        struct tm *tm_ptr;
 
-# ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_lock( &ldap_int_gmtime_mutex );
-# endif /* LDAP_R_COMPILE */
-
+       LDAP_MUTEX_LOCK( &ldap_int_gmtime_mutex );
        tm_ptr = gmtime( timep );
        if ( tm_ptr == NULL ) {
                result = NULL;
@@ -155,10 +151,7 @@ ldap_pvt_gmtime( const time_t *timep, struct tm *result )
        } else {
                *result = *tm_ptr;
        }
-
-# ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_unlock( &ldap_int_gmtime_mutex );
-# endif /* LDAP_R_COMPILE */
+       LDAP_MUTEX_UNLOCK( &ldap_int_gmtime_mutex );
 
        return result;
 }
@@ -170,10 +163,7 @@ ldap_pvt_localtime( const time_t *timep, struct tm *result )
 {
        struct tm *tm_ptr;
 
-# ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_lock( &ldap_int_gmtime_mutex );
-# endif /* LDAP_R_COMPILE */
-
+       LDAP_MUTEX_LOCK( &ldap_int_gmtime_mutex );
        tm_ptr = localtime( timep );
        if ( tm_ptr == NULL ) {
                result = NULL;
@@ -181,10 +171,7 @@ ldap_pvt_localtime( const time_t *timep, struct tm *result )
        } else {
                *result = *tm_ptr;
        }
-
-# ifdef LDAP_R_COMPILE
-       ldap_pvt_thread_mutex_unlock( &ldap_int_gmtime_mutex );
-# endif /* LDAP_R_COMPILE */
+       LDAP_MUTEX_UNLOCK( &ldap_int_gmtime_mutex );
 
        return result;
 }
@@ -284,7 +271,7 @@ ldap_pvt_gettime( struct lutil_tm *ltm )
        t = tv.tv_sec;
 
        if ( tv.tv_sec < prevTv.tv_sec
-               || ( tv.tv_sec == prevTv.tv_sec && tv.tv_usec == prevTv.tv_usec )) {
+               || ( tv.tv_sec == prevTv.tv_sec && tv.tv_usec <= prevTv.tv_usec )) {
                subs++;
        } else {
                subs = 0;
@@ -380,7 +367,7 @@ int ldap_pvt_gethostbyname_a(
        int     retval;
        *buf = NULL;
        
-       ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
+       LDAP_MUTEX_LOCK( &ldap_int_resolv_mutex );
        
        he = gethostbyname( name );
        
@@ -395,7 +382,7 @@ int ldap_pvt_gethostbyname_a(
                retval = 0;
        }
        
-       ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
+       LDAP_MUTEX_UNLOCK( &ldap_int_resolv_mutex );
        
        return retval;
 #else  
@@ -439,13 +426,9 @@ int ldap_pvt_get_hname(
        int rc;
 #if defined( HAVE_GETNAMEINFO )
 
-#if defined( LDAP_R_COMPILE )
-       ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
-#endif
+       LDAP_MUTEX_LOCK( &ldap_int_resolv_mutex );
        rc = getnameinfo( sa, len, name, namelen, NULL, 0, 0 );
-#if defined( LDAP_R_COMPILE )
-       ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
-#endif
+       LDAP_MUTEX_UNLOCK( &ldap_int_resolv_mutex );
        if ( rc ) *err = (char *)AC_GAI_STRERROR( rc );
        return rc;
 
@@ -509,9 +492,7 @@ int ldap_pvt_get_hname(
        LDAP_FREE(buf);
 #else /* HAVE_GETHOSTBYADDR_R */
 
-#if defined( LDAP_R_COMPILE )
-       ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
-#endif
+       LDAP_MUTEX_LOCK( &ldap_int_resolv_mutex );
        hp = gethostbyaddr( addr, alen, sa->sa_family );
        if (hp) {
                strncpy( name, hp->h_name, namelen );
@@ -520,9 +501,7 @@ int ldap_pvt_get_hname(
                rc = h_errno;
                *err = (char *)HSTRERROR( h_errno );
        }
-#if defined( LDAP_R_COMPILE )
-       ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
-#endif
+       LDAP_MUTEX_UNLOCK( &ldap_int_resolv_mutex );
 
 #endif /* !HAVE_GETHOSTBYADDR_R */
        return rc;
@@ -577,8 +556,7 @@ int ldap_pvt_gethostbyaddr_a(
        int     retval;
        *buf = NULL;   
        
-       ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
-       
+       LDAP_MUTEX_LOCK( &ldap_int_resolv_mutex );
        he = gethostbyaddr( addr, len, type );
        
        if (he==NULL) {
@@ -591,8 +569,7 @@ int ldap_pvt_gethostbyaddr_a(
                *result = resbuf;
                retval = 0;
        }
-       
-       ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
+       LDAP_MUTEX_UNLOCK( &ldap_int_resolv_mutex );
        
        return retval;