+2024-07-26 Bruno Haible <bruno@clisp.org>
+
+ sys_un: Avoid compilation error in C++ <string.h> on glibc systems.
+ * m4/sys_un_h.m4 (gl_SYS_UN_H): Require AC_CANONICAL_HOST. Set
+ GL_GENERATE_SYS_UN_H to true on glibc systems. Invoke
+ gl_CHECK_NEXT_HEADERS. Initialize HAVE_SYS_UN_H.
+ * lib/sys_un.in.h: Use include_next and a split double-inclusion guard.
+ In C++ mode, include <stddef.h> and <string.h> first.
+ * modules/sys_un (Depends-on): Add include_next.
+ (Makefile.am): Substitute INCLUDE_NEXT, PRAGMA_SYSTEM_HEADER,
+ PRAGMA_COLUMNS, NEXT_SYS_UN_H, HAVE_SYS_UN_H. Arrange to remove 'sys'
+ directory at "make mostlyclean".
+
2024-07-26 Bruno Haible <bruno@clisp.org>
xstrtol, xstrtoll tests: Improve comment.
/* Written by Collin Funk. */
#ifndef _@GUARD_PREFIX@_SYS_UN_H
-#define _@GUARD_PREFIX@_SYS_UN_H 1
-/* Windows requires <winsock2.h> to be included before <afunix.h>. */
-#if @HAVE_WINSOCK2_H@
-# include <winsock2.h>
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
#endif
-#if @HAVE_AFUNIX_H@
-# include <afunix.h>
+@PRAGMA_COLUMNS@
+
+#if @HAVE_SYS_UN_H@
+
+/* On glibc, in C++ mode with clang, <stddef.h> and <string.h> need to be
+ included before <sys/un.h>, because otherwise <sys/un.h> includes them inside
+ an 'extern "C" { ... }' block, which leads to compilation errors in gnulib's
+ <string.h> override. */
+# if defined __cplusplus
+# include <stddef.h>
+# include <string.h>
+# endif
+
+/* The include_next requires a split double-inclusion guard. */
+# @INCLUDE_NEXT@ @NEXT_SYS_UN_H@
+
#endif
+#ifndef _@GUARD_PREFIX@_SYS_UN_H
+#define _@GUARD_PREFIX@_SYS_UN_H 1
+
+#if !@HAVE_SYS_UN_H@
+
+/* A platform that lacks <sys/un.h>. */
+
+/* Windows requires <winsock2.h> to be included before <afunix.h>. */
+# if @HAVE_WINSOCK2_H@
+# include <winsock2.h>
+# endif
+# if @HAVE_AFUNIX_H@
+# include <afunix.h>
+# endif
+
/* If a platform does not support AF_UNIX sockets 'struct sockaddr_un' will
not be defined. You may use HAVE_UNIXSOCKET after including <config.h>. */
#endif
+
+#endif /* _@GUARD_PREFIX@_SYS_UN_H */
+#endif /* _@GUARD_PREFIX@_SYS_UN_H */
# sys_un_h.m4
-# serial 1
+# serial 2
dnl Copyright 2024 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
AC_DEFUN_ONCE([gl_SYS_UN_H],
[
+ AC_REQUIRE([AC_CANONICAL_HOST])
+
dnl Check if UNIX domain sockets are supported.
AC_REQUIRE([gl_SOCKET_FAMILY_UNIX])
GL_GENERATE_SYS_UN_H=false
-
if test $gl_cv_socket_unix = yes; then
-
dnl Check if using a Windows version that supports AF_UNIX.
dnl See <https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/>.
if test "$ac_cv_header_winsock2_h" = yes \
&& test "$ac_cv_header_afunix_h" = yes; then
GL_GENERATE_SYS_UN_H=true
fi
+ case "$host_os" in
+ dnl On glibc systems, we need to include <string.h> before <sys/un.h>,
+ dnl at least in C++ mode with clang.
+ *-gnu* | gnu*) GL_GENERATE_SYS_UN_H=true ;;
+ esac
fi
- dnl Checked in gl_SOCKET_FAMILY_UNIX.
- if test "$ac_cv_header_afunix_h" = yes; then
- HAVE_AFUNIX_H=1
- else
- HAVE_AFUNIX_H=0
+ if $GL_GENERATE_SYS_UN_H; then
+ AC_CHECK_HEADERS([sys/un.h])
+ gl_CHECK_NEXT_HEADERS([sys/un.h])
+
+ if test $ac_cv_header_sys_un_h = yes; then
+ HAVE_SYS_UN_H=1
+ else
+ HAVE_SYS_UN_H=0
+ fi
+ AC_SUBST([HAVE_SYS_UN_H])
+
+ dnl Checked in gl_SOCKET_FAMILY_UNIX.
+ if test "$ac_cv_header_afunix_h" = yes; then
+ HAVE_AFUNIX_H=1
+ else
+ HAVE_AFUNIX_H=0
+ fi
+ AC_SUBST([HAVE_AFUNIX_H])
fi
- AC_SUBST([HAVE_AFUNIX_H])
])
Depends-on:
gen-header
+include_next
sys_socket
configure.ac:
@NMD@ $(AM_V_GEN)$(MKDIR_P) '%reldir%'
$(gl_V_at)$(SED_HEADER_STDOUT) \
-e 's|@''GUARD_PREFIX''@|${gl_include_guard_prefix}|g' \
+ -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+ -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+ -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+ -e 's|@''NEXT_SYS_UN_H''@|$(NEXT_SYS_UN_H)|g' \
+ -e 's|@''HAVE_SYS_UN_H''@|$(HAVE_SYS_UN_H)|g' \
-e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
-e 's|@''HAVE_AFUNIX_H''@|$(HAVE_AFUNIX_H)|g' \
- $(srcdir)/sys_un.in.h > $@-t
+ $(srcdir)/sys_un.in.h > $@-t
$(AM_V_at)mv $@-t $@
else
sys/un.h: $(top_builddir)/config.status
rm -f $@
endif
MOSTLYCLEANFILES += sys/un.h sys/un.h-t
+MOSTLYCLEANDIRS += sys
Include:
<sys/un.h>