arpa_inet: Use the common idioms with C++ support.
authorBruno Haible <bruno@clisp.org>
Sun, 26 Dec 2010 22:56:33 +0000 (23:56 +0100)
committerBruno Haible <bruno@clisp.org>
Mon, 27 Dec 2010 00:30:14 +0000 (01:30 +0100)
* lib/arpa_inet.in.h: Include c++defs.h.
(inet_ntop, inet_pton): Declare using the macros with C++ namespace
support.
* modules/arpa_inet (Depends-on): Add c++defs.
(Makefile.am): Substitute the contents of c++defs.h.
* modules/arpa_inet-tests (Depends-on): Add arpa_inet-c++-tests.
* modules/arpa_inet-c++-tests: New file.
* tests/test-arpa_inet-c++.cc: New file.

ChangeLog
lib/arpa_inet.in.h
modules/arpa_inet
modules/arpa_inet-c++-tests [new file with mode: 0644]
modules/arpa_inet-tests
tests/test-arpa_inet-c++.cc [new file with mode: 0644]

index 300eccb..4a76cc8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-12-26  Bruno Haible  <bruno@clisp.org>
+
+       arpa_inet: Use the common idioms with C++ support.
+       * lib/arpa_inet.in.h: Include c++defs.h.
+       (inet_ntop, inet_pton): Declare using the macros with C++ namespace
+       support.
+       * modules/arpa_inet (Depends-on): Add c++defs.
+       (Makefile.am): Substitute the contents of c++defs.h.
+       * modules/arpa_inet-tests (Depends-on): Add arpa_inet-c++-tests.
+       * modules/arpa_inet-c++-tests: New file.
+       * tests/test-arpa_inet-c++.cc: New file.
+
 2010-12-25  Bruno Haible  <bruno@clisp.org>
 
        Fix more C++ link errors on Solaris 8.
index fbf0842..cfbd977 100644 (file)
 #ifndef _GL_ARPA_INET_H
 #define _GL_ARPA_INET_H
 
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
 /* The definition of _GL_ARG_NONNULL is copied here.  */
 
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
 
 #if @GNULIB_INET_NTOP@
 # if !@HAVE_DECL_INET_NTOP@
@@ -69,10 +68,15 @@ extern "C" {
 
    For more details, see the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/inet_ntop.html>.  */
-extern const char *inet_ntop (int af, const void *restrict src,
-                              char *restrict dst, socklen_t cnt)
-     _GL_ARG_NONNULL ((2, 3));
+_GL_FUNCDECL_SYS (inet_ntop, const char *,
+                  (int af, const void *restrict src,
+                   char *restrict dst, socklen_t cnt)
+                  _GL_ARG_NONNULL ((2, 3)));
 # endif
+_GL_CXXALIAS_SYS (inet_ntop, const char *,
+                  (int af, const void *restrict src,
+                   char *restrict dst, socklen_t cnt));
+_GL_CXXALIASWARN (inet_ntop);
 #elif defined GNULIB_POSIXCHECK
 # undef inet_ntop
 # if HAVE_RAW_DECL_INET_NTOP
@@ -83,9 +87,13 @@ _GL_WARN_ON_USE (inet_ntop, "inet_ntop is unportable - "
 
 #if @GNULIB_INET_PTON@
 # if !@HAVE_DECL_INET_PTON@
-extern int inet_pton (int af, const char *restrict src, void *restrict dst)
-     _GL_ARG_NONNULL ((2, 3));
+_GL_FUNCDECL_SYS (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst)
+                  _GL_ARG_NONNULL ((2, 3)));
 # endif
+_GL_CXXALIAS_SYS (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst));
+_GL_CXXALIASWARN (inet_pton);
 #elif defined GNULIB_POSIXCHECK
 # undef inet_pton
 # if HAVE_RAW_DECL_INET_PTON
@@ -94,9 +102,6 @@ _GL_WARN_ON_USE (inet_pton, "inet_pton is unportable - "
 # endif
 #endif
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif /* _GL_ARPA_INET_H */
 #endif /* _GL_ARPA_INET_H */
index cec5d6c..34b9881 100644 (file)
@@ -7,6 +7,7 @@ m4/arpa_inet_h.m4
 
 Depends-on:
 arg-nonnull
+c++defs
 include_next
 sys_socket
 warn-on-use
@@ -20,7 +21,7 @@ BUILT_SOURCES += arpa/inet.h
 
 # We need the following in order to create <arpa/inet.h> when the system
 # doesn't have one.
-arpa/inet.h: arpa_inet.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H)
+arpa/inet.h: arpa_inet.in.h $(CXXDEFS_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
        $(AM_V_at)$(MKDIR_P) arpa
        $(AM_V_GEN)rm -f $@-t $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
@@ -34,6 +35,7 @@ arpa/inet.h: arpa_inet.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H)
              -e 's|@''GNULIB_INET_PTON''@|$(GNULIB_INET_PTON)|g' \
              -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \
              -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
              -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              < $(srcdir)/arpa_inet.in.h; \
diff --git a/modules/arpa_inet-c++-tests b/modules/arpa_inet-c++-tests
new file mode 100644 (file)
index 0000000..5d20170
--- /dev/null
@@ -0,0 +1,19 @@
+Files:
+tests/test-arpa_inet-c++.cc
+tests/signature.h
+
+Status:
+c++-test
+
+Depends-on:
+ansi-c++-opt
+
+configure.ac:
+
+Makefile.am:
+if ANSICXX
+TESTS += test-arpa_inet-c++
+check_PROGRAMS += test-arpa_inet-c++
+test_arpa_inet_c___SOURCES = test-arpa_inet-c++.cc
+test_arpa_inet_c___LDADD = $(LDADD) $(INET_NTOP_LIB) $(INET_PTON_LIB) $(LIBSOCKET)
+endif
index 8c31fde..d6706f9 100644 (file)
@@ -2,6 +2,7 @@ Files:
 tests/test-arpa_inet.c
 
 Depends-on:
+arpa_inet-c++-tests
 
 configure.ac:
 
diff --git a/tests/test-arpa_inet-c++.cc b/tests/test-arpa_inet-c++.cc
new file mode 100644 (file)
index 0000000..da08e48
--- /dev/null
@@ -0,0 +1,41 @@
+/* Test of <arpa/inet.h> substitute in C++ mode.
+   Copyright (C) 2010 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 Bruno Haible <bruno@clisp.org>, 2010.  */
+
+#define GNULIB_NAMESPACE gnulib
+#include <config.h>
+
+#include <arpa/inet.h>
+
+#include "signature.h"
+
+
+#if GNULIB_TEST_INET_NTOP
+SIGNATURE_CHECK (GNULIB_NAMESPACE::inet_ntop, const char *,
+                 (int, const void *, char *, socklen_t));
+#endif
+
+#if GNULIB_TEST_INET_PTON
+SIGNATURE_CHECK (GNULIB_NAMESPACE::inet_pton, int,
+                 (int, const char *, void *));
+#endif
+
+
+int
+main ()
+{
+}