Initial step towards a configure time ares_socklen_t definition
authorYang Tse <yangsita@gmail.com>
Tue, 28 Apr 2009 16:47:33 +0000 (16:47 +0000)
committerYang Tse <yangsita@gmail.com>
Tue, 28 Apr 2009 16:47:33 +0000 (16:47 +0000)
.cvsignore
Makefile.am
Makefile.inc
acinclude.m4
ahost.c
ares.h
ares_build.h.dist [new file with mode: 0644]
ares_build.h.in [new file with mode: 0644]
ares_rules.h [new file with mode: 0644]
configure.ac
setup.h

index 014ee7f..ab7a77b 100644 (file)
@@ -6,6 +6,7 @@ Makefile.in
 aclocal.m4
 adig
 ahost
+ares_build.h
 ares_version.h.dist
 autom4te.cache
 config.guess
index 7b61565..a2c32a6 100644 (file)
@@ -46,7 +46,9 @@ noinst_PROGRAMS =$(PROGS)
 EXTRA_DIST = AUTHORS CHANGES README.cares Makefile.inc Makefile.dj        \
  Makefile.m32 Makefile.netware Makefile.vc6 $(man_MANS) $(MSVCFILES)      \
  config-win32.h RELEASE-NOTES libcares.pc.in buildconf get_ver.awk maketgz \
- TODO
+ TODO ares_build.h.in
+
+DISTCLEANFILES = ares_build.h
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libcares.pc
@@ -96,7 +98,8 @@ libcares_la_SOURCES = $(CSOURCES) $(HHEADERS)
 # where to install the c-ares headers
 libcares_ladir = $(includedir)
 # what headers to install on 'make install':
-libcares_la_HEADERS = ares.h ares_version.h ares_dns.h
+libcares_la_HEADERS = ares.h ares_version.h ares_dns.h \
+       ares_build.h ares_rules.h
 
 ahost_SOURCES = ahost.c ares_getopt.c ares_getopt.h
 ahost_LDADD = $(top_builddir)/$(lib_LTLIBRARIES)
index 07b71bd..586fe06 100644 (file)
@@ -10,7 +10,8 @@ ares_parse_ns_reply.c ares_llist.c ares__timeval.c ares_strcasecmp.c
 
 HHEADERS = ares.h ares_private.h setup.h ares_dns.h ares_version.h          \
  nameser.h inet_net_pton.h inet_ntop.h ares_ipv6.h bitncmp.h setup_once.h   \
- ares_llist.h ares_strdup.h ares_strcasecmp.h ares_writev.h
+ ares_llist.h ares_strdup.h ares_strcasecmp.h ares_writev.h ares_build.h    \
+ ares_rules.h
 
 MANPAGES= ares_destroy.3 ares_expand_name.3 ares_expand_string.3 ares_fds.3 \
  ares_free_hostent.3 ares_free_string.3 ares_gethostbyaddr.3               \
index 790d1c7..8cadce1 100644 (file)
@@ -1737,6 +1737,168 @@ AC_DEFUN([CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC], [
 ])
 
 
+dnl CARES_DEFINE_UNQUOTED (VARIABLE, [VALUE])
+dnl -------------------------------------------------
+dnl Like AC_DEFINE_UNQUOTED this macro will define a C preprocessor
+dnl symbol that can be further used in custom template configuration
+dnl files. This macro, unlike AC_DEFINE_UNQUOTED, does not use a third
+dnl argument for the description. Symbol definitions done with this
+dnl macro are intended to be exclusively used in handcrafted *.h.in
+dnl template files. Contrary to what AC_DEFINE_UNQUOTED does, this one
+dnl prevents autoheader generation and insertion of symbol template
+dnl stub and definition into the first configuration header file. Do
+dnl not use this macro as a replacement for AC_DEFINE_UNQUOTED, each
+dnl one serves different functional needs.
+
+AC_DEFUN([CARES_DEFINE_UNQUOTED], [
+cat >>confdefs.h <<_EOF
+[@%:@define] $1 ifelse($#, 2, [$2], 1)
+_EOF
+])
+
+
+dnl CARES_CONFIGURE_LONG
+dnl -------------------------------------------------
+dnl Find out the size of long as reported by sizeof() and define
+dnl CARES_SIZEOF_LONG as appropriate to be used in template file
+dnl ares_build.h.in to properly configure the library.
+dnl The size of long is a build time characteristic and as such
+dnl must be recorded in ares_build.h
+
+AC_DEFUN([CARES_CONFIGURE_LONG], [
+  if test -z "$ac_cv_sizeof_long" ||
+    test "$ac_cv_sizeof_long" -eq "0"; then
+    AC_MSG_ERROR([cannot find out size of long.])
+  fi
+  CARES_DEFINE_UNQUOTED([CARES_SIZEOF_LONG], [$ac_cv_sizeof_long])
+])
+
+
+dnl CARES_CONFIGURE_ARES_SOCKLEN_T
+dnl -------------------------------------------------
+dnl Find out suitable ares_socklen_t data type definition and size, making
+dnl appropriate definitions for template file ares_build.h.in
+dnl to properly configure and use the library.
+dnl
+dnl The need for the ares_socklen_t definition arises mainly to properly
+dnl interface HP-UX systems which on one hand have a typedef'ed socklen_t
+dnl data type which is 32 or 64-Bit wide depending on the data model being
+dnl used, and that on the other hand is only actually used when interfacing
+dnl the X/Open sockets provided in the xnet library.
+
+AC_DEFUN([CARES_CONFIGURE_ARES_SOCKLEN_T], [
+  AC_REQUIRE([CARES_INCLUDES_WS2TCPIP])dnl
+  AC_REQUIRE([CARES_INCLUDES_SYS_SOCKET])dnl
+  AC_REQUIRE([CARES_PREPROCESS_CALLCONV])dnl
+  #
+  AC_MSG_CHECKING([for ares_socklen_t data type])
+  cares_typeof_ares_socklen_t="unknown"
+  for arg1 in int SOCKET; do
+    for arg2 in 'struct sockaddr' void; do
+      for t in socklen_t int size_t 'unsigned int' long 'unsigned long' void; do
+        if test "$cares_typeof_ares_socklen_t" = "unknown"; then
+          AC_COMPILE_IFELSE([
+            AC_LANG_PROGRAM([[
+              $cares_includes_ws2tcpip
+              $cares_includes_sys_socket
+              $cares_preprocess_callconv
+              extern int FUNCALLCONV getpeername($arg1, $arg2 *, $t *);
+            ]],[[
+              $t *lenptr = 0;
+              if(0 != getpeername(0, 0, lenptr))
+                return 1;
+            ]])
+          ],[
+            cares_typeof_ares_socklen_t="$t"
+          ])
+        fi
+      done
+    done
+  done
+  for t in socklen_t int; do
+    if test "$cares_typeof_ares_socklen_t" = "void"; then
+      AC_COMPILE_IFELSE([
+        AC_LANG_PROGRAM([[
+          $cares_includes_sys_socket
+          typedef $t ares_socklen_t;
+        ]],[[
+          ares_socklen_t dummy;
+        ]])
+      ],[
+        cares_typeof_ares_socklen_t="$t"
+      ])
+    fi
+  done
+  AC_MSG_RESULT([$cares_typeof_ares_socklen_t])
+  if test "$cares_typeof_ares_socklen_t" = "void" ||
+    test "$cares_typeof_ares_socklen_t" = "unknown"; then
+    AC_MSG_ERROR([cannot find data type for ares_socklen_t.])
+  fi
+  #
+  AC_MSG_CHECKING([size of ares_socklen_t])
+  cares_sizeof_ares_socklen_t="unknown"
+  cares_pull_headers_socklen_t="unknown"
+  if test "$ac_cv_header_ws2tcpip_h" = "yes"; then
+    tst_pull_header_checks='none ws2tcpip'
+    tst_size_checks='4'
+  else
+    tst_pull_header_checks='none systypes syssocket'
+    tst_size_checks='4 8 2'
+  fi
+  for tst_size in $tst_size_checks; do
+    for tst_pull_headers in $tst_pull_header_checks; do
+      if test "$cares_sizeof_ares_socklen_t" = "unknown"; then
+        case $tst_pull_headers in
+          ws2tcpip)
+            tmp_includes="$cares_includes_ws2tcpip"
+            ;;
+          systypes)
+            tmp_includes="$cares_includes_sys_types"
+            ;;
+          syssocket)
+            tmp_includes="$cares_includes_sys_socket"
+            ;;
+          *)
+            tmp_includes=""
+            ;;
+        esac
+        AC_COMPILE_IFELSE([
+          AC_LANG_PROGRAM([[
+            $tmp_includes
+            typedef $cares_typeof_ares_socklen_t ares_socklen_t;
+            typedef char dummy_arr[sizeof(ares_socklen_t) == $tst_size ? 1 : -1];
+          ]],[[
+            ares_socklen_t dummy;
+          ]])
+        ],[
+          cares_sizeof_ares_socklen_t="$tst_size"
+          cares_pull_headers_socklen_t="$tst_pull_headers"
+        ])
+      fi
+    done
+  done
+  AC_MSG_RESULT([$cares_sizeof_ares_socklen_t])
+  if test "$cares_sizeof_ares_socklen_t" = "unknown"; then
+    AC_MSG_ERROR([cannot find out size of ares_socklen_t.])
+  fi
+  #
+  case $cares_pull_headers_socklen_t in
+    ws2tcpip)
+      CARES_DEFINE_UNQUOTED([CARES_PULL_WS2TCPIP_H])
+      ;;
+    systypes)
+      CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_TYPES_H])
+      ;;
+    syssocket)
+      CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_TYPES_H])
+      CARES_DEFINE_UNQUOTED([CARES_PULL_SYS_SOCKET_H])
+      ;;
+  esac
+  CARES_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SOCKLEN_T], [$cares_typeof_ares_socklen_t])
+  CARES_DEFINE_UNQUOTED([CARES_SIZEOF_ARES_SOCKLEN_T], [$cares_sizeof_ares_socklen_t])
+])
+
+
 dnl This macro determines if the specified struct exists in the specified file
 dnl Syntax:
 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])
diff --git a/ahost.c b/ahost.c
index 567c7a0..46ec735 100644 (file)
--- a/ahost.c
+++ b/ahost.c
@@ -42,6 +42,7 @@
 #include "inet_ntop.h"
 #include "inet_net_pton.h"
 #include "ares_getopt.h"
+#include "ares_ipv6.h"
 
 #ifndef HAVE_STRDUP
 #  include "ares_strdup.h"
diff --git a/ares.h b/ares.h
index ab829db..585e350 100644 (file)
--- a/ares.h
+++ b/ares.h
@@ -19,6 +19,9 @@
 #ifndef ARES__H
 #define ARES__H
 
+#include "ares_build.h"  /* c-ares build definitions */
+#include "ares_rules.h"  /* c-ares rules enforcement */
+
 /*
  * Define WIN32 when build target is Win32 API
  */
diff --git a/ares_build.h.dist b/ares_build.h.dist
new file mode 100644 (file)
index 0000000..16a5cc5
--- /dev/null
@@ -0,0 +1,234 @@
+#ifndef __CARES_BUILD_H
+#define __CARES_BUILD_H
+
+/* $Id$ */
+
+/* Copyright (C) 2009 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
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  M.I.T. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ */
+
+/* ================================================================ */
+/*               NOTES FOR CONFIGURE CAPABLE SYSTEMS                */
+/* ================================================================ */
+
+/*
+ * NOTE 1:
+ * -------
+ *
+ * See file ares_build.h.in, run configure, and forget that this file
+ * exists it is only used for non-configure systems.
+ * But you can keep reading if you want ;-)
+ *
+ */
+
+/* ================================================================ */
+/*                 NOTES FOR NON-CONFIGURE SYSTEMS                  */
+/* ================================================================ */
+
+/*
+ * NOTE 1:
+ * -------
+ *
+ * Nothing in this file is intended to be modified or adjusted by the
+ * c-ares library user nor by the c-ares library builder.
+ *
+ * If you think that something actually needs to be changed, adjusted
+ * or fixed in this file, then, report it on the c-ares development
+ * mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
+ *
+ * Try to keep one section per platform, compiler and architecture,
+ * otherwise, if an existing section is reused for a different one and
+ * later on the original is adjusted, probably the piggybacking one can
+ * be adversely changed.
+ *
+ * In order to differentiate between platforms/compilers/architectures
+ * use only compiler built in predefined preprocessor symbols.
+ *
+ * This header file shall only export symbols which are 'cares' or 'CARES'
+ * prefixed, otherwise public name space would be polluted.
+ *
+ * NOTE 2:
+ * -------
+ *
+ * Right now you might be staring at file ares_build.h.dist or ares_build.h,
+ * this is due to the following reason: file ares_build.h.dist is renamed
+ * to ares_build.h when the c-ares source code distribution archive file is
+ * created.
+ *
+ * File ares_build.h.dist is not included in the distribution archive.
+ * File ares_build.h is not present in the CVS tree.
+ *
+ * The distributed ares_build.h file is only intended to be used on systems
+ * which can not run the also distributed configure script.
+ *
+ * On systems capable of running the configure script, the configure process
+ * will overwrite the distributed ares_build.h file with one that is suitable
+ * and specific to the library being configured and built, which is generated
+ * from the ares_build.h.in template file.
+ *
+ * If you check out from CVS on a non-configure platform, you must run the
+ * appropriate buildconf* script to set up ares_build.h and other local files.
+ *
+ */
+
+/* ================================================================ */
+/*  DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE  */
+/* ================================================================ */
+
+#ifdef CARES_SIZEOF_LONG
+#  error "CARES_SIZEOF_LONG shall not be defined except in ares_build.h"
+   Error Compilation_aborted_CARES_SIZEOF_LONG_already_defined
+#endif
+
+#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
+#  error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
+   Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
+#endif
+
+#ifdef CARES_SIZEOF_ARES_SOCKLEN_T
+#  error "CARES_SIZEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
+   Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_already_defined
+#endif
+
+/* ================================================================ */
+/*    EXTERNAL INTERFACE SETTINGS FOR NON-CONFIGURE SYSTEMS ONLY    */
+/* ================================================================ */
+
+#if defined(__DJGPP__) || defined(__GO32__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T int
+#  define CARES_SIZEOF_ARES_SOCKLEN_T 4
+
+#elif defined(__SALFORDC__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__BORLANDC__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__TURBOC__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__WATCOMC__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__POCC__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__LCC__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__SYMBIAN32__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__MWERKS__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(_WIN32_WCE)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__MINGW32__)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__VMS)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#  define CARES_SIZEOF_ARES_SOCKLEN_T -1
+
+#elif defined(__OS400__)
+#  if defined(__ILEC400__)
+#    define CARES_SIZEOF_LONG           4
+#    define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#    define CARES_SIZEOF_ARES_SOCKLEN_T -1
+#  endif
+
+#elif defined(__MVS__)
+#  if defined(__IBMC__) || defined(__IBMCPP__)
+#    if defined(_ILP32)
+#      define CARES_SIZEOF_LONG           4
+#      define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#      define CARES_SIZEOF_ARES_SOCKLEN_T -1
+#    elif defined(_LP64)
+#      define CARES_SIZEOF_LONG           8
+#      define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#      define CARES_SIZEOF_ARES_SOCKLEN_T -1
+#    endif
+#  endif
+
+#elif defined(__370__)
+#  if defined(__IBMC__) || defined(__IBMCPP__)
+#    if defined(_ILP32)
+#      define CARES_SIZEOF_LONG           4
+#      define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#      define CARES_SIZEOF_ARES_SOCKLEN_T -1
+#    elif defined(_LP64)
+#      define CARES_SIZEOF_LONG           8
+#      define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#      define CARES_SIZEOF_ARES_SOCKLEN_T -1
+#    endif
+#  endif
+
+/* ===================================== */
+/*    KEEP MSVC THE PENULTIMATE ENTRY    */
+/* ===================================== */
+
+#elif defined(_MSC_VER)
+#  define CARES_SIZEOF_LONG           4
+#  define CARES_TYPEOF_ARES_SOCKLEN_T int
+#  define CARES_SIZEOF_ARES_SOCKLEN_T 4
+
+/* ===================================== */
+/*    KEEP GENERIC GCC THE LAST ENTRY    */
+/* ===================================== */
+
+#elif defined(__GNUC__)
+#  if defined(__i386__) || defined(__ppc__)
+#    define CARES_SIZEOF_LONG           4
+#    define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#    define CARES_SIZEOF_ARES_SOCKLEN_T -1
+#  elif defined(__x86_64__) || defined(__ppc64__)
+#    define CARES_SIZEOF_LONG           8
+#    define CARES_TYPEOF_ARES_SOCKLEN_T FIXME
+#    define CARES_SIZEOF_ARES_SOCKLEN_T -1
+#  endif
+
+#else
+#  error "Unknown non-configure build target!"
+   Error Compilation_aborted_Unknown_non_configure_build_target
+#endif
+
+/* Data type definition of ares_socklen_t. */
+
+#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
+  typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
+#endif
+
+#endif /* __CARES_BUILD_H */
diff --git a/ares_build.h.in b/ares_build.h.in
new file mode 100644 (file)
index 0000000..21ef2fe
--- /dev/null
@@ -0,0 +1,99 @@
+#ifndef __CARES_BUILD_H
+#define __CARES_BUILD_H
+
+/* $Id$ */
+
+/* Copyright (C) 2009 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
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  M.I.T. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ */
+
+/* ================================================================ */
+/*               NOTES FOR CONFIGURE CAPABLE SYSTEMS                */
+/* ================================================================ */
+
+/*
+ * NOTE 1:
+ * -------
+ *
+ * Nothing in this file is intended to be modified or adjusted by the
+ * c-ares library user nor by the c-ares library builder.
+ *
+ * If you think that something actually needs to be changed, adjusted
+ * or fixed in this file, then, report it on the c-ares development
+ * mailing list: http://cool.haxx.se/mailman/listinfo/c-ares/
+ *
+ * This header file shall only export symbols which are 'cares' or 'CARES'
+ * prefixed, otherwise public name space would be polluted.
+ *
+ * NOTE 2:
+ * -------
+ *
+ * Right now you might be staring at file ares_build.h.in or ares_build.h,
+ * this is due to the following reason:
+ *
+ * On systems capable of running the configure script, the configure process
+ * will overwrite the distributed ares_build.h file with one that is suitable
+ * and specific to the library being configured and built, which is generated
+ * from the ares_build.h.in template file.
+ *
+ */
+
+/* ================================================================ */
+/*  DEFINITION OF THESE SYMBOLS SHALL NOT TAKE PLACE ANYWHERE ELSE  */
+/* ================================================================ */
+
+#ifdef CARES_SIZEOF_LONG
+#  error "CARES_SIZEOF_LONG shall not be defined except in ares_build.h"
+   Error Compilation_aborted_CARES_SIZEOF_LONG_already_defined
+#endif
+
+#ifdef CARES_TYPEOF_ARES_SOCKLEN_T
+#  error "CARES_TYPEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
+   Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_already_defined
+#endif
+
+#ifdef CARES_SIZEOF_ARES_SOCKLEN_T
+#  error "CARES_SIZEOF_ARES_SOCKLEN_T shall not be defined except in ares_build.h"
+   Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_already_defined
+#endif
+
+/* ================================================================ */
+/*  EXTERNAL INTERFACE SETTINGS FOR CONFIGURE CAPABLE SYSTEMS ONLY  */
+/* ================================================================ */
+
+/* Configure process defines this to 1 when it finds out that system   */
+/* header file sys/types.h must be included by the external interface. */
+#undef CARES_PULL_SYS_TYPES_H
+#ifdef CARES_PULL_SYS_TYPES_H
+#  include <sys/types.h>
+#endif
+
+/* Configure process defines this to 1 when it finds out that system    */
+/* header file sys/socket.h must be included by the external interface. */
+#undef CARES_PULL_SYS_SOCKET_H
+#ifdef CARES_PULL_SYS_SOCKET_H
+#  include <sys/socket.h>
+#endif
+
+/* The size of `long', as computed by sizeof. */
+#undef CARES_SIZEOF_LONG
+
+/* Integral data type used for ares_socklen_t. */
+#undef CARES_TYPEOF_ARES_SOCKLEN_T
+
+/* The size of `ares_socklen_t', as computed by sizeof. */
+#undef CARES_SIZEOF_ARES_SOCKLEN_T
+
+/* Data type definition of ares_socklen_t. */
+typedef CARES_TYPEOF_ARES_SOCKLEN_T ares_socklen_t;
+
+#endif /* __CARES_BUILD_H */
diff --git a/ares_rules.h b/ares_rules.h
new file mode 100644 (file)
index 0000000..95751b0
--- /dev/null
@@ -0,0 +1,144 @@
+#ifndef __CARES_RULES_H
+#define __CARES_RULES_H
+
+/* $Id$ */
+
+/* Copyright (C) 2009 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
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of M.I.T. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  M.I.T. makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ */
+
+/* ================================================================ */
+/*                    COMPILE TIME SANITY CHECKS                    */
+/* ================================================================ */
+
+/*
+ * NOTE 1:
+ * -------
+ *
+ * All checks done in this file are intentionally placed in a public
+ * header file which is pulled by ares.h when an application is
+ * being built using an already built c-ares library. Additionally
+ * this file is also included and used when building the library.
+ *
+ * If compilation fails on this file it is certainly sure that the
+ * problem is elsewhere. It could be a problem in the ares_build.h
+ * header file, or simply that you are using different compilation
+ * settings than those used to build the library.
+ *
+ * Nothing in this file is intended to be modified or adjusted by the
+ * c-ares library user nor by the c-ares library builder.
+ *
+ * Do not deactivate any check, these are done to make sure that the
+ * library is properly built and used.
+ *
+ * You can find further help on the c-ares development mailing list:
+ * http://cool.haxx.se/mailman/listinfo/c-ares/
+ *
+ * NOTE 2
+ * ------
+ *
+ * Some of the following compile time checks are based on the fact
+ * that the dimension of a constant array can not be a negative one.
+ * In this way if the compile time verification fails, the compilation
+ * will fail issuing an error. The error description wording is compiler
+ * dependant but it will be quite similar to one of the following:
+ *
+ *   "negative subscript or subscript is too large"
+ *   "array must have at least one element"
+ *   "-1 is an illegal array size"
+ *   "size of array is negative"
+ *
+ * If you are building an application which tries to use an already
+ * built c-ares library and you are getting this kind of errors on
+ * this file, it is a clear indication that there is a mismatch between
+ * how the library was built and how you are trying to use it for your
+ * application. Your already compiled or binary library provider is the
+ * only one who can give you the details you need to properly use it.
+ */
+
+/*
+ * Verify that some macros are actually defined.
+ */
+
+#ifndef CARES_SIZEOF_LONG
+#  error "CARES_SIZEOF_LONG definition is missing!"
+   Error Compilation_aborted_CARES_SIZEOF_LONG_is_missing
+#endif
+
+#ifndef CARES_TYPEOF_ARES_SOCKLEN_T
+#  error "CARES_TYPEOF_ARES_SOCKLEN_T definition is missing!"
+   Error Compilation_aborted_CARES_TYPEOF_ARES_SOCKLEN_T_is_missing
+#endif
+
+#ifndef CARES_SIZEOF_ARES_SOCKLEN_T
+#  error "CARES_SIZEOF_ARES_SOCKLEN_T definition is missing!"
+   Error Compilation_aborted_CARES_SIZEOF_ARES_SOCKLEN_T_is_missing
+#endif
+
+/*
+ * Macros private to this header file.
+ */
+
+#define CareschkszEQ(t, s) sizeof(t) == s ? 1 : -1
+
+#define CareschkszGE(t1, t2) sizeof(t1) >= sizeof(t2) ? 1 : -1
+
+/*
+ * Verify that the size previously defined and expected for long
+ * is the same as the one reported by sizeof() at compile time.
+ */
+
+typedef char
+  __cares_rule_01__
+    [CareschkszEQ(long, CARES_SIZEOF_LONG)];
+
+/*
+ * Verify that the size previously defined and expected for
+ * ares_socklen_t is actually the the same as the one reported
+ * by sizeof() at compile time.
+ */
+
+typedef char
+  __cares_rule_02__
+    [CareschkszEQ(ares_socklen_t, CARES_SIZEOF_ARES_SOCKLEN_T)];
+
+/*
+ * Verify at compile time that the size of ares_socklen_t as reported
+ * by sizeof() is greater or equal than the one reported for int for
+ * the current compilation.
+ */
+
+typedef char
+  __cares_rule_03__
+    [CareschkszGE(ares_socklen_t, int)];
+
+/* ================================================================ */
+/*          EXTERNALLY AND INTERNALLY VISIBLE DEFINITIONS           */
+/* ================================================================ */
+
+/*
+ * Get rid of macros private to this header file.
+ */
+
+#undef CareschkszEQ
+#undef CareschkszGE
+
+/*
+ * Get rid of macros not intended to exist beyond this point.
+ */
+
+#undef CARES_PULL_SYS_TYPES_H
+#undef CARES_PULL_SYS_SOCKET_H
+
+#undef CARES_TYPEOF_ARES_SOCKLEN_T
+
+#endif /* __CARES_RULES_H */
index aca5e94..8482f1a 100644 (file)
@@ -7,7 +7,7 @@ AC_INIT([c-ares], [-],
 CARES_OVERRIDE_AUTOCONF
 
 AC_CONFIG_SRCDIR([ares_ipv6.h])
-AM_CONFIG_HEADER([config.h])
+AM_CONFIG_HEADER([config.h ares_build.h])
 AM_MAINTAINER_MODE
 
 CARES_CHECK_OPTION_DEBUG
@@ -489,7 +489,9 @@ AC_HEADER_TIME
 CURL_CHECK_STRUCT_TIMEVAL
 
 AC_CHECK_SIZEOF(size_t)
+AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
+CARES_CONFIGURE_LONG
 AC_CHECK_SIZEOF(time_t)
 
 AC_CHECK_TYPE(long long,
@@ -525,6 +527,8 @@ AC_CHECK_TYPE([bool],[
 #endif
 ])
 
+CARES_CONFIGURE_ARES_SOCKLEN_T
+
 # Check for socklen_t or equivalent
 CURL_CHECK_TYPE_SOCKLEN_T
 
diff --git a/setup.h b/setup.h
index 585d504..794ef9a 100644 (file)
--- a/setup.h
+++ b/setup.h
@@ -3,7 +3,7 @@
 
 /* $Id$ */
 
-/* Copyright (C) 2004 - 2008 by Daniel Stenberg et al
+/* Copyright (C) 2004 - 2009 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
 
 #endif /* HAVE_CONFIG_H */
 
+/* ================================================================ */
+/* Definition of preprocessor macros/symbols which modify compiler  */
+/* behaviour or generated code characteristics must be done here,   */
+/* as appropriate, before any system header file is included. It is */
+/* also possible to have them defined in the config file included   */
+/* before this point. As a result of all this we frown inclusion of */
+/* system header files in our config files, avoid this at any cost. */
+/* ================================================================ */
+
 /*
  * Tru64 needs _REENTRANT set for a few function prototypes and
  * things to appear in the system header files. Unixware needs it
 #  endif
 #endif
 
+/* ================================================================ */
+/*  If you need to include a system header file for your platform,  */
+/*  please, do it beyond the point further indicated in this file.  */
+/* ================================================================ */
+
+/*
+ * c-ares external interface definitions are also used internally,
+ * and might also include required system header files to define them.
+ */
+
+#include <ares_build.h>
+
+/*
+ * Compile time sanity checks must also be done when building the library.
+ */
+
+#include <ares_rules.h>
+
+/* ================================================================ */
+/* No system header file shall be included in this file before this */
+/* point. The only allowed ones are those included from curlbuild.h */
+/* ================================================================ */
+
 /*
  * Include header files for windows builds before redefining anything.
  * Use this preproessor block only to include or exclude windows.h,