diff --git a/clients/tools/ldapdelete.c b/clients/tools/ldapdelete.c
index 93b9f0de61983ad9b720095f44022053b0766596..9a0bf901a8486e9a7400184806a487748c504e34 100644
--- a/clients/tools/ldapdelete.c
+++ b/clients/tools/ldapdelete.c
@@ -8,6 +8,7 @@
 
 #include <ac/socket.h>
 #include <ac/string.h>
+#include <ac/unistd.h>
 
 #include <lber.h>
 #include <ldap.h>
diff --git a/clients/tools/ldapmodrdn.c b/clients/tools/ldapmodrdn.c
index a00d259d340120a8e0adb81086f94b9172c19b0f..76b6154f9fd84fb01edf201f26a05cbf9ef6a41c 100644
--- a/clients/tools/ldapmodrdn.c
+++ b/clients/tools/ldapmodrdn.c
@@ -8,6 +8,7 @@
 #include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/time.h>
+#include <ac/unistd.h>
 
 #include <lber.h>
 #include <ldap.h>
diff --git a/include/ac/stdarg.h b/include/ac/stdarg.h
new file mode 100644
index 0000000000000000000000000000000000000000..8b805c8abc15c1c56b534c18370e04023ef1d7f6
--- /dev/null
+++ b/include/ac/stdarg.h
@@ -0,0 +1,14 @@
+/* Generic stdarg.h */
+
+#ifndef _AC_STDARG_H
+#define _AC_STDARG_H 1
+
+#if defined( HAVE_STDARG_H ) && \
+	( defined( __STDC__ ) || defined( _WIN32 ) )
+#	include <stdarg.h>
+#	define HAVE_STDARG 1
+#else
+#	include <varargs.h>
+#endif
+
+#endif /* _AC_STDARG_H */
diff --git a/libraries/liblber/decode.c b/libraries/liblber/decode.c
index 80f11de4363a8691842ed9a19962ec50d5e02731..e67b288b5572c286140967f449dbecf38b931e00 100644
--- a/libraries/liblber/decode.c
+++ b/libraries/liblber/decode.c
@@ -19,11 +19,7 @@
 #include <stdlib.h>
 #endif
 
-#if defined( HAVE_STDARG_H ) && __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+#include <ac/stdarg.h>
 
 #include <ac/string.h>
 #include <ac/socket.h>
@@ -370,7 +366,7 @@ ber_next_element( BerElement *ber, unsigned long *len, char *last )
 /* VARARGS */
 unsigned long
 ber_scanf
-#if defined( HAVE_STDARG_H ) && __STDC__
+#if HAVE_STDARG
 	( BerElement *ber, char *fmt, ... )
 #else
 	( va_alist )
@@ -378,7 +374,7 @@ va_dcl
 #endif
 {
 	va_list		ap;
-#if !(defined( HAVE_STDARG_H ) && __STDC__)
+#ifndef HAVE_STDARG
 	BerElement	*ber;
 	char		*fmt;
 #endif
@@ -389,7 +385,7 @@ va_dcl
 	long		*l;
 	unsigned long	rc, tag, len;
 
-#if defined( HAVE_STDARG_H ) && __STDC__
+#ifdef HAVE_STDARG
 	va_start( ap, fmt );
 #else
 	va_start( ap );
diff --git a/libraries/liblber/encode.c b/libraries/liblber/encode.c
index f2aee16a790eab628215d8dba622714bc01c4067..b320a2eb569237519bcd67bcfb7666895ab84feb 100644
--- a/libraries/liblber/encode.c
+++ b/libraries/liblber/encode.c
@@ -16,12 +16,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#if defined( HAVE_STDARG_H ) && __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
+#include <ac/stdarg.h>
 #include <ac/socket.h>
 #include <ac/string.h>
 
@@ -509,7 +504,7 @@ ber_put_set( BerElement *ber )
 /* VARARGS */
 int
 ber_printf
-#if defined( HAVE_STDARG_H ) && __STDC__
+#ifdef HAVE_STDARG
 	( BerElement *ber, char *fmt, ... )
 #else
 	( va_alist )
@@ -517,7 +512,7 @@ va_dcl
 #endif
 {
 	va_list		ap;
-#if !(defined( HAVE_STDARG_H ) && __STDC__)
+#ifndef HAVE_STDARG
 	BerElement	*ber;
 	char		*fmt;
 #endif
@@ -526,7 +521,7 @@ va_dcl
 	int		rc, i;
 	unsigned long	len;
 
-#if defined( HAVE_STDARG_H ) && __STDC__
+#ifdef HAVE_STDARG
 	va_start( ap, fmt );
 #else
 	va_start( ap );
diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c
index 0083cc0591ed17c5bd29ce38281200bafef9ca9e..9d15b1c3429727dba2dcd3edc52fb6bab6473cb2 100644
--- a/libraries/libldap/os-ip.c
+++ b/libraries/libldap/os-ip.c
@@ -56,7 +56,7 @@ ldap_connect_to_host( Sockbuf *sb, char *host, unsigned long address,
 
 	connected = use_hp = 0;
 
-	if ( host != NULL && ( address = inet_addr( host )) == -1UL ) {
+	if ( host != NULL && ( address = inet_addr( host )) == (unsigned long) -1L ) {
 		if ( (hp = gethostbyname( host )) == NULL ) {
 #ifdef HAVE_WINSOCK
 			errno = WSAGetLastError();