Another longstanding part of the sys/socket.h specification:

    * The <sys/socket.h> header shall define the socklen_t type, which
      is an integer type of width of at least 32 bits; see APPLICATION
      USAGE.
    * The <sys/socket.h> header shall define the sa_family_t unsigned
      integer type.

On mingw I see 'typedef int socklen_t' in ws2tcpip.h. But sa_family_t is
undefined so Gnulib uses 'unsigned short' which is conforming.

I've committed a test for this to catch any other platforms. If Windows
satisfies it then hopefully nowhere else should be a problem.

Collin

>From 24e4b2dca4ac04795211d307a2ee20c62184d2b5 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 23 Jul 2024 19:00:28 -0700
Subject: [PATCH] sys_socket tests: Improve checks for socklen_t and
 sa_family_t.

* modules/sys_socket-tests (Depends-on): Add intprops.
* tests/test-sys_socket.c: Check that socklen_t is at least 32 bits
wide. Check that sa_family_t is unsigned.
---
 ChangeLog                |  7 +++++++
 modules/sys_socket-tests |  1 +
 tests/test-sys_socket.c  | 10 ++++++++++
 3 files changed, 18 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 0c252e22d0..cf51073474 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-07-23  Collin Funk  <collin.fu...@gmail.com>
+
+	sys_socket tests: Improve checks for socklen_t and sa_family_t.
+	* modules/sys_socket-tests (Depends-on): Add intprops.
+	* tests/test-sys_socket.c: Check that socklen_t is at least 32 bits
+	wide. Check that sa_family_t is unsigned.
+
 2024-07-23  Bruno Haible  <br...@clisp.org>
 
 	getopt-posix, getopt-gnu tests: Avoid test failure on mingw.
diff --git a/modules/sys_socket-tests b/modules/sys_socket-tests
index b0bb4356ca..0e0ef6c45e 100644
--- a/modules/sys_socket-tests
+++ b/modules/sys_socket-tests
@@ -3,6 +3,7 @@ tests/test-sys_socket.c
 
 Depends-on:
 assert-h
+intprops
 sys_socket-c++-tests
 
 configure.ac:
diff --git a/tests/test-sys_socket.c b/tests/test-sys_socket.c
index 6fbfb98a70..5c1ad11540 100644
--- a/tests/test-sys_socket.c
+++ b/tests/test-sys_socket.c
@@ -38,6 +38,16 @@ struct msghdr msg;
 
 #include <errno.h>
 
+#include "intprops.h"
+
+/* POSIX requires that 'socklen_t' is an integer type with a width of at
+   least 32 bits.  */
+static_assert (32 <= TYPE_WIDTH (socklen_t));
+
+/* POSIX requires that sa_family_t is an unsigned integer type.  */
+static_assert (! TYPE_SIGNED (sa_family_t));
+
+
 int
 main (void)
 {
-- 
2.45.2

Reply via email to