Add netdb.h replacement module.
authorSimon Josefsson <simon@josefsson.org>
Wed, 15 Oct 2008 12:48:59 +0000 (14:48 +0200)
committerSimon Josefsson <simon@josefsson.org>
Wed, 15 Oct 2008 12:48:59 +0000 (14:48 +0200)
Currently empty and unused, but that will change soon.

ChangeLog
MODULES.html.sh
doc/posix-headers/netdb.texi
lib/netdb.in.h [new file with mode: 0644]
m4/netdb_h.m4 [new file with mode: 0644]
modules/netdb [new file with mode: 0644]
modules/netdb-tests [new file with mode: 0644]
tests/test-netdb.c [new file with mode: 0644]

index 64b95e5..721d69e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2008-10-15  Simon Josefsson  <simon@josefsson.org>
 
+       * modules/netdb, modules/netdb-tests: New file.
+       * m4/netdb_h.m4: New file.
+       * lib/netdb.in.h: Add, currently just an empty file pending
+       definitions.
+       * tests/test-netdb.c: New file.
+       * doc/posix-headers/netdb.texi: Mention that we replace it if
+       needed.
+       * MODULES.html.sh (Support for systems lacking POSIX:2001): Add
+       netdb.
+
+2008-10-15  Simon Josefsson  <simon@josefsson.org>
+
        * doc/gnulib.texi (Getaddrinfo and WINVER): Sync documentation
        with code.
 
index abecc26..9597f09 100755 (executable)
@@ -2134,6 +2134,7 @@ func_all_modules ()
   func_module mkdir
   func_module mkdtemp
   func_module mkstemp
+  func_module netdb
   func_module netinet_in
   func_module open
   func_module perror
index 8d33ba8..1654013 100644 (file)
@@ -7,11 +7,11 @@ Gnulib module: ---
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This header file is missing on some platforms:
+mingw, BeOS.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
-@item
-This header file is missing on some platforms:
-mingw, BeOS.
 @end itemize
diff --git a/lib/netdb.in.h b/lib/netdb.in.h
new file mode 100644 (file)
index 0000000..0aa0691
--- /dev/null
@@ -0,0 +1,48 @@
+/* Provide a netdb.h header file for systems lacking it (read: MinGW).
+   Copyright (C) 2008 Free Software Foundation, Inc.
+   Written by Simon Josefsson.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* This file is supposed to be used on platforms that lack <netdb.h>.
+   It is intended to provide definitions and prototypes needed by an
+   application.  */
+
+#ifndef _GL_NETDB_H
+
+#if @HAVE_NETDB_H@
+
+@PRAGMA_SYSTEM_HEADER@
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_NETDB_H@
+
+#endif
+
+#ifndef _GL_NETDB_H
+#define _GL_NETDB_H
+
+#if @HAVE_NETDB_H@
+
+/* Declarations for a platform that has <netdb.h>.  */
+
+#else
+
+/* Declarations for a platform that has <netdb.h>.  */
+
+#endif /* HAVE_NETDB_H */
+
+#endif /* _GL_NETDB_H */
+#endif /* _GL_NETDB_H */
diff --git a/m4/netdb_h.m4 b/m4/netdb_h.m4
new file mode 100644 (file)
index 0000000..d6d729f
--- /dev/null
@@ -0,0 +1,43 @@
+# netdb_h.m4 serial 1
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_HEADER_NETDB],
+[
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
+  AC_CACHE_CHECK([whether <netdb.h> is self-contained],
+    [gl_cv_header_netdb_h_selfcontained],
+    [
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]],
+                                        [[struct hostent h;]])],
+        [gl_cv_header_netdb_h_selfcontained=yes],
+        [gl_cv_header_netdb_h_selfcontained=no])
+    ])
+  if test $gl_cv_header_netdb_h_selfcontained = yes; then
+    NETDB_H=''
+  else
+    NETDB_H='netdb.h'
+    gl_CHECK_NEXT_HEADERS([netdb.h])
+    if test $ac_cv_header_netdb_h = yes; then
+      HAVE_NETDB_H=1
+    else
+      HAVE_NETDB_H=0
+    fi
+    AC_SUBST([HAVE_NETDB_H])
+  fi
+  AC_SUBST([NETDB_H])
+])
+
+AC_DEFUN([gl_NETDB_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_NETDB_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_NETDB_H_DEFAULTS],
+[
+  :
+])
diff --git a/modules/netdb b/modules/netdb
new file mode 100644 (file)
index 0000000..21e4ff4
--- /dev/null
@@ -0,0 +1,38 @@
+Description:
+A <netdb.h> for systems lacking it.
+
+Files:
+lib/netdb.in.h
+m4/netdb_h.m4
+
+Depends-on:
+include_next
+
+configure.ac:
+gl_HEADER_NETDB
+
+Makefile.am:
+BUILT_SOURCES += $(NETDB_H)
+
+# We need the following in order to create <netdb.h> when the system
+# doesn't have one that works with the given compiler.
+netdb.h: netdb.in.h
+       rm -f $@-t $@
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''NEXT_NETDB_H''@|$(NEXT_NETDB_H)|g' \
+             -e 's|@''HAVE_NETDB_H''@|$(HAVE_NETDB_H)|g' \
+             < $(srcdir)/netdb.in.h; \
+       } > $@-t
+       mv $@-t $@
+MOSTLYCLEANFILES += netdb.h netdb.h-t
+
+Include:
+#include <netdb.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Simon Josefsson
diff --git a/modules/netdb-tests b/modules/netdb-tests
new file mode 100644 (file)
index 0000000..d1ef7e1
--- /dev/null
@@ -0,0 +1,13 @@
+Files:
+tests/test-netdb.c
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-netdb
+check_PROGRAMS += test-netdb
+
+License:
+LGPL
diff --git a/tests/test-netdb.c b/tests/test-netdb.c
new file mode 100644 (file)
index 0000000..cde9105
--- /dev/null
@@ -0,0 +1,29 @@
+/* Test of <netdb.h> substitute.
+   Copyright (C) 2007-2008 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Simon Josefsson <simon@josefsson.org>, 2008.  */
+
+#include <config.h>
+#include <netdb.h>
+
+/* Check that the 'struct hostent' type is defined.  */
+struct hostent t1;
+
+int
+main (void)
+{
+  return 0;
+}