]> Savannah Git Hosting - gnulib.git/commitdiff
sys_un-h: Ensure that <sys/un.h> defines sa_family_t.
authorBruno Haible <bruno@clisp.org>
Fri, 10 Jan 2025 22:52:54 +0000 (23:52 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 10 Jan 2025 22:54:51 +0000 (23:54 +0100)
* lib/sys_un.in.h: Include <sys/socket.h> or define sa_family_t
explicitly.
* m4/sys_socket_h.m4 (gl_PREREQ_SYS_SA_FAMILY): New macro, extracted
from gl_SYS_SOCKET_H.
(gl_SYS_SOCKET_H): Invoke it.
(gl_SYS_SOCKET_H_DEFAULTS): Don't initialize HAVE_SA_FAMILY_T.
* m4/sys_un_h.m4 (gl_SYS_UN_H): Invoke gl_PREREQ_SYS_SA_FAMILY. Test
whether <sys/un.h> defines sa_family_t. If not, set GL_GENERATE_SYS_UN_H
to true.
* modules/sys_un-h (Makefile.am): Substitute HAVE_SA_FAMILY_T,
HAVE_SA_FAMILY_T_IN_SYS_UN_H.
* tests/test-sys_un-h.c: Include intprops.h. Verify that sa_family_t is
defined and an unsigned integer type.
* modules/sys_un-h-tests (Depends-on): Add intprops.
* doc/posix-headers/sys_un.texi: Mention the problem with sa_family_t.

ChangeLog
doc/posix-headers/sys_un.texi
lib/sys_un.in.h
m4/sys_socket_h.m4
m4/sys_un_h.m4
modules/sys_un-h
modules/sys_un-h-tests
tests/test-sys_un-h.c

index 5bf647530a28a7eef7246aa56c5e6c7a9906f3d6..2b9083c406a1dc8d4bae223c934be6a89778e18a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2025-01-10  Bruno Haible  <bruno@clisp.org>
+
+       sys_un-h: Ensure that <sys/un.h> defines sa_family_t.
+       * lib/sys_un.in.h: Include <sys/socket.h> or define sa_family_t
+       explicitly.
+       * m4/sys_socket_h.m4 (gl_PREREQ_SYS_SA_FAMILY): New macro, extracted
+       from gl_SYS_SOCKET_H.
+       (gl_SYS_SOCKET_H): Invoke it.
+       (gl_SYS_SOCKET_H_DEFAULTS): Don't initialize HAVE_SA_FAMILY_T.
+       * m4/sys_un_h.m4 (gl_SYS_UN_H): Invoke gl_PREREQ_SYS_SA_FAMILY. Test
+       whether <sys/un.h> defines sa_family_t. If not, set GL_GENERATE_SYS_UN_H
+       to true.
+       * modules/sys_un-h (Makefile.am): Substitute HAVE_SA_FAMILY_T,
+       HAVE_SA_FAMILY_T_IN_SYS_UN_H.
+       * tests/test-sys_un-h.c: Include intprops.h. Verify that sa_family_t is
+       defined and an unsigned integer type.
+       * modules/sys_un-h-tests (Depends-on): Add intprops.
+       * doc/posix-headers/sys_un.texi: Mention the problem with sa_family_t.
+
 2025-01-10  Bruno Haible  <bruno@clisp.org>
 
        sys_wait-h: Document WCOREDUMP fix.
index 63be81d8d2bf853534b2a336447c80e594c005b2..338f5826c83a236bf5075558f63da1e4cc12529a 100644 (file)
@@ -14,6 +14,9 @@ Portability problems fixed by Gnulib:
 @c <https://blogs.windows.com/windows-insider/2017/12/19/announcing-windows-10-insider-preview-build-17063-pc/>
 This header file is missing on some platforms:
 mingw, MSVC 14.
+@item
+This header file does not define the @code{sa_family_t} type on some platforms:
+Cygwin 3.5.5, mingw, MSVC 14.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index e2ffcc6c6f8d9d647ab4ae317761b43802b0ee6f..a32444a2534f178858487199c01b6ff08d2488f1 100644 (file)
 
 #endif
 
+#if !@HAVE_SA_FAMILY_T_IN_SYS_UN_H@
+# if @HAVE_SA_FAMILY_T@
+/* A platform that has <sys/un.h> but which — unlike <sys/socket.h> — does not
+   define the 'sa_family_t' type.  */
+#  include <sys/socket.h>
+# else
+/* A platform which does not define the 'sa_family_t' type at all.
+   Define it here in the same way as in <sys/socket.h>.  */
+#  if !GNULIB_defined_sa_family_t
+/* On OS/2 kLIBC, sa_family_t is unsigned char unless TCPV40HDRS is defined. */
+#   if !defined __KLIBC__ || defined TCPV40HDRS
+typedef unsigned short  sa_family_t;
+#   else
+typedef unsigned char   sa_family_t;
+#   endif
+#   define GNULIB_defined_sa_family_t 1
+#  endif
+# endif
+#endif
+
 #endif /* _@GUARD_PREFIX@_SYS_UN_H */
 #endif /* _@GUARD_PREFIX@_SYS_UN_H */
index 75e974857246450fa858290cf1dabfc7f90decc4..08b1c6d929203d3802133246b4f820964c02fd05 100644 (file)
@@ -1,5 +1,5 @@
 # sys_socket_h.m4
-# serial 29
+# serial 30
 dnl Copyright (C) 2005-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -53,24 +53,10 @@ AC_DEFUN_ONCE([gl_SYS_SOCKET_H],
   fi
   # We need to check for ws2tcpip.h now.
   gl_PREREQ_SYS_H_SOCKET
-  AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
-  /* sys/types.h is not needed according to POSIX, but the
-     sys/socket.h in i386-unknown-freebsd4.10 and
-     powerpc-apple-darwin5.5 required it. */
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-])
   if test $ac_cv_type_struct_sockaddr_storage = no; then
     HAVE_STRUCT_SOCKADDR_STORAGE=0
   fi
-  if test $ac_cv_type_sa_family_t = no; then
-    HAVE_SA_FAMILY_T=0
-  fi
+  gl_PREREQ_SYS_SA_FAMILY
   if test $ac_cv_type_struct_sockaddr_storage != no; then
     AC_CHECK_MEMBERS([struct sockaddr_storage.ss_family],
       [],
@@ -159,6 +145,32 @@ AC_DEFUN([gl_PREREQ_SYS_H_WS2TCPIP],
   AC_SUBST([HAVE_WS2TCPIP_H])
 ])
 
+# Common prerequisites of the <sys/socket.h> replacement and of the <sys/un.h>
+# replacement.
+# Sets and substitutes HAVE_SA_FAMILY_T.
+AC_DEFUN([gl_PREREQ_SYS_SA_FAMILY],
+[
+  AC_REQUIRE([gl_CHECK_SOCKET_HEADERS])
+  AC_CHECK_TYPES([struct sockaddr_storage, sa_family_t],,,[
+  /* sys/types.h is not needed according to POSIX, but the
+     sys/socket.h in i386-unknown-freebsd4.10 and
+     powerpc-apple-darwin5.5 required it. */
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+])
+  if test $ac_cv_type_sa_family_t = yes; then
+    HAVE_SA_FAMILY_T=1
+  else
+    HAVE_SA_FAMILY_T=0
+  fi
+  AC_SUBST([HAVE_SA_FAMILY_T])
+])
+
 # gl_SYS_SOCKET_MODULE_INDICATOR([modulename])
 # sets the shell variable that indicates the presence of the given module
 # to a C preprocessor expression that will evaluate to 1.
@@ -203,6 +215,5 @@ AC_DEFUN([gl_SYS_SOCKET_H_DEFAULTS],
   HAVE_STRUCT_SOCKADDR_STORAGE=1; AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE])
   HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY=1;
                         AC_SUBST([HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY])
-  HAVE_SA_FAMILY_T=1;   AC_SUBST([HAVE_SA_FAMILY_T])
   HAVE_ACCEPT4=1;       AC_SUBST([HAVE_ACCEPT4])
 ])
index 2990345ebef7a624b5c05c8529d7b7c158e69304..7f2ad2e6ca7ff4937fc6c35f0dfe13f97f3c0a6b 100644 (file)
@@ -1,5 +1,5 @@
 # sys_un_h.m4
-# serial 2
+# serial 3
 dnl Copyright 2024-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -13,6 +13,28 @@ AC_DEFUN_ONCE([gl_SYS_UN_H],
   dnl Check if UNIX domain sockets are supported.
   AC_REQUIRE([gl_SOCKET_FAMILY_UNIX])
 
+  gl_PREREQ_SYS_SA_FAMILY
+  AC_CACHE_CHECK([whether <sys/un.h> defines sa_family_t],
+    [gl_cv_type_sys_un_sa_family_t],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM([[
+          #include <stddef.h>
+          #include <string.h>
+          #include <sys/un.h>
+          ]], [[
+          sa_family_t f;
+          ]])
+       ],
+       [gl_cv_type_sys_un_sa_family_t=yes],
+       [gl_cv_type_sys_un_sa_family_t=no])
+    ])
+  if test $gl_cv_type_sys_un_sa_family_t = yes; then
+    HAVE_SA_FAMILY_T_IN_SYS_UN_H=1
+  else
+    HAVE_SA_FAMILY_T_IN_SYS_UN_H=0
+  fi
+  AC_SUBST([HAVE_SA_FAMILY_T_IN_SYS_UN_H])
+
   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.
@@ -27,6 +49,9 @@ AC_DEFUN_ONCE([gl_SYS_UN_H],
       *-gnu* | gnu*) GL_GENERATE_SYS_UN_H=true ;;
     esac
   fi
+  if test $HAVE_SA_FAMILY_T_IN_SYS_UN_H = 0; then
+    GL_GENERATE_SYS_UN_H=true
+  fi
 
   if $GL_GENERATE_SYS_UN_H; then
     AC_CHECK_HEADERS([sys/un.h])
index 3c1b3ba505f71d66a031faf2f3888e5d209c3f0a..8f80b8b4c72ea084884a022c0bf665b9858adaa4 100644 (file)
@@ -32,6 +32,8 @@ sys/un.h: sys_un.in.h $(top_builddir)/config.status
              -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' \
+             -e 's|@''HAVE_SA_FAMILY_T''@|$(HAVE_SA_FAMILY_T)|g' \
+             -e 's|@''HAVE_SA_FAMILY_T_IN_SYS_UN_H''@|$(HAVE_SA_FAMILY_T_IN_SYS_UN_H)|g' \
              $(srcdir)/sys_un.in.h > $@-t
        $(AM_V_at)mv $@-t $@
 else
index e2e3bf7860cbad0e2f03e0badd16c22d3088f171..6722ce2bea75fc3eb07df6e97aa869a6bcbbc0b7 100644 (file)
@@ -3,6 +3,7 @@ tests/test-sys_un-h.c
 
 Depends-on:
 assert-h
+intprops
 sys_un-h-c++-tests
 
 configure.ac:
index 5755f2f93544ba60d1dd2b23f2fde2ab92980a46..4eac2742ecae5accfe22b0b9773c3f3731d5ae32 100644 (file)
 /* Specification.  */
 # include <sys/un.h>
 
+# include "intprops.h"
+
+/* POSIX requires that sa_family_t is an unsigned integer type.  */
+static_assert (! TYPE_SIGNED (sa_family_t));
+
 int
 main (void)
 {