Support Watt-32 under Win32.
[platform/upstream/c-ares.git] / setup.h
diff --git a/setup.h b/setup.h
index 619a285..9fe081b 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -1,7 +1,9 @@
-#ifndef ARES_SETUP_H
-#define ARES_SETUP_H
+#ifndef __ARES_SETUP_H
+#define __ARES_SETUP_H
 
-/* Copyright (C) 2004 - 2005 by Daniel Stenberg et al
+/* $Id$ */
+
+/* Copyright (C) 2004 - 2008 by Daniel Stenberg et al
  *
  * Permission to use, copy, modify, and distribute this software and its
  * documentation for any purpose and without fee is hereby granted, provided
  * without express or implied warranty.
  */
 
+/*
+ * Define WIN32 when build target is Win32 API
+ */
+
+#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
+#define WIN32
+#endif
+
+/*
+ * Include configuration script results or hand-crafted
+ * configuration file for platforms which lack config tool.
+ */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #else
-/* simple work-around for now, for systems without configure support */
+
+#ifdef WIN32
+#include "config-win32.h"
+#endif
+
+#endif /* HAVE_CONFIG_H */
+
+/*
+ * Tru64 needs _REENTRANT set for a few function prototypes and
+ * things to appear in the system header files. Unixware needs it
+ * to build proper reentrant code. Others may also need it.
+ */
+
+#ifdef NEED_REENTRANT
+#  ifndef _REENTRANT
+#    define _REENTRANT
+#  endif
+#endif
+
+/*
+ * Include header files for windows builds before redefining anything.
+ * Use this preproessor block only to include or exclude windows.h,
+ * winsock2.h, ws2tcpip.h or winsock.h. Any other windows thing belongs
+ * to any other further and independant block.  Under Cygwin things work
+ * just as under linux (e.g. <sys/socket.h>) and the winsock headers should
+ * never be included when __CYGWIN__ is defined.  configure script takes
+ * care of this, not defining HAVE_WINDOWS_H, HAVE_WINSOCK_H, HAVE_WINSOCK2_H,
+ * neither HAVE_WS2TCPIP_H when __CYGWIN__ is defined.
+ */
+
+#ifdef HAVE_WINDOWS_H
+#  ifndef WIN32_LEAN_AND_MEAN
+#    define WIN32_LEAN_AND_MEAN
+#  endif
+#  include <windows.h>
+#  ifdef HAVE_WINSOCK2_H
+#    include <winsock2.h>
+#    ifdef HAVE_WS2TCPIP_H
+#       include <ws2tcpip.h>
+#    endif
+#  else
+#    ifdef HAVE_WINSOCK_H
+#      include <winsock.h>
+#    endif
+#  endif
+#endif
+
+/*
+ * Define USE_WINSOCK to 2 if we have and use WINSOCK2 API, else
+ * define USE_WINSOCK to 1 if we have and use WINSOCK  API, else
+ * undefine USE_WINSOCK.
+ */
+
+#undef USE_WINSOCK
+
+#ifdef HAVE_WINSOCK2_H
+#  define USE_WINSOCK 2
+#else
+#  ifdef HAVE_WINSOCK_H
+#    define USE_WINSOCK 1
+#  endif
+#endif
+
+/*
+ * Work-arounds for systems without configure support
+ */
+
+#ifndef HAVE_CONFIG_H
+
+#if defined(__DJGPP__) || (defined(__WATCOMC__) && (__WATCOMC__ >= 1240)) || \
+    defined(__POCC__)
+#else
 #define ssize_t int
-#define socklen_t int
 #endif
 
-/* Recent autoconf versions define these symbols in config.h. We don't want
-   them (since they collide with the libcurl ones when we build
-   --enable-debug) so we undef them again here. */
+#endif /* HAVE_CONFIG_H */
+
+/*
+ * Recent autoconf versions define these symbols in config.h. We don't
+ * want them (since they collide with the libcurl ones when we build
+ *  --enable-debug) so we undef them again here.
+ */
+
 #undef PACKAGE_STRING
 #undef PACKAGE_TARNAME
 #undef PACKAGE_VERSION
 #undef VERSION
 #undef PACKAGE
 
-/* now typedef our socket type */
-#if defined(WIN32) && !defined(WATT32)
-#include <winsock.h>
-typedef SOCKET ares_socket_t;
-#define ARES_SOCKET_BAD INVALID_SOCKET
-#else
-typedef int ares_socket_t;
-#define ARES_SOCKET_BAD -1
-#endif
-
-/* Assume a few thing unless they're set by configure
+/*
+ * Assume a few thing unless they're set by configure
  */
-#if !defined(HAVE_SYS_TIME_H) && !defined(_MSC_VER)
+
+#if !defined(HAVE_SYS_TIME_H) && !defined(_MSC_VER) && !defined(__WATCOMC__)
 #define HAVE_SYS_TIME_H
 #endif
 
@@ -58,7 +140,7 @@ typedef int ares_socket_t;
 #endif
 
 #if (defined(WIN32) || defined(WATT32)) && \
-   !(defined(__MINGW32__) || defined(NETWARE))
+   !(defined(__MINGW32__) || defined(NETWARE) || defined(__DJGPP__))
 /* protos for the functions we provide in windows_port.c */
 int ares_strncasecmp(const char *s1, const char *s2, int n);
 int ares_strcasecmp(const char *s1, const char *s2);
@@ -68,6 +150,11 @@ int ares_strcasecmp(const char *s1, const char *s2);
    same */
 #define strncasecmp(a,b,c) ares_strncasecmp(a,b,c)
 #define strcasecmp(a,b) ares_strcasecmp(a,b)
+#ifdef _MSC_VER
+#  if _MSC_VER >= 1400
+#    define strdup(a) _strdup(a)
+#  endif
+#endif
 #endif
 
 /* IPv6 compatibility */
@@ -79,4 +166,12 @@ int ares_strcasecmp(const char *s1, const char *s2);
 #endif
 #endif
 
-#endif /* ARES_SETUP_H */
+/*
+ * Include macros and defines that should only be processed once.
+ */
+
+#ifndef __SETUP_ONCE_H
+#include "setup_once.h"
+#endif
+
+#endif /* __ARES_SETUP_H */