From 2752918fa8a8c06e06f276d6f17a79a2f12aeb0c Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Thu, 25 Jul 2024 01:12:43 +0200
Subject: [PATCH] Avoid false
 getsockopt_used_without_requesting_gnulib_module_getsockopt.

* modules/getsockopt (configure.ac): Invoke gl_MODULE_INDICATOR.
* lib/sys_socket.in.h (getsockopt): Don't define to
getsockopt_used_without_requesting_gnulib_module_getsockopt if the
gnulib module 'getsockopt' is in use under the same configure.ac.
---
 ChangeLog           | 6 ++++++
 lib/sys_socket.in.h | 6 ++++--
 modules/getsockopt  | 1 +
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9a48a5e070..f1fcc7306f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2024-07-24  Bruno Haible  <bruno@clisp.org>
 
+	Avoid false getsockopt_used_without_requesting_gnulib_module_getsockopt.
+	* modules/getsockopt (configure.ac): Invoke gl_MODULE_INDICATOR.
+	* lib/sys_socket.in.h (getsockopt): Don't define to
+	getsockopt_used_without_requesting_gnulib_module_getsockopt if the
+	gnulib module 'getsockopt' is in use under the same configure.ac.
+
 	Avoid false getsockname_used_without_requesting_gnulib_module_getsockname.
 	* modules/getsockname (configure.ac): Invoke gl_MODULE_INDICATOR.
 	* lib/sys_socket.in.h (getsockname): Don't define to
diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h
index f19403d1f0..ce217cdadb 100644
--- a/lib/sys_socket.in.h
+++ b/lib/sys_socket.in.h
@@ -504,8 +504,10 @@ _GL_CXXALIAS_SYS_CAST (getsockopt, int,
 # endif
 _GL_CXXALIASWARN (getsockopt);
 #elif @HAVE_WINSOCK2_H@
-# undef getsockopt
-# define getsockopt getsockopt_used_without_requesting_gnulib_module_getsockopt
+# if !GNULIB_GETSOCKOPT
+#  undef getsockopt
+#  define getsockopt getsockopt_used_without_requesting_gnulib_module_getsockopt
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef getsockopt
 # if HAVE_RAW_DECL_GETSOCKOPT
diff --git a/modules/getsockopt b/modules/getsockopt
index 7749995a60..26d53f7534 100644
--- a/modules/getsockopt
+++ b/modules/getsockopt
@@ -18,6 +18,7 @@ AC_REQUIRE([gl_SYS_SOCKET_H])
 gl_CONDITIONAL([GL_COND_OBJ_GETSOCKOPT],
                [test "$ac_cv_header_winsock2_h" = yes])
 gl_SYS_SOCKET_MODULE_INDICATOR([getsockopt])
+gl_MODULE_INDICATOR([getsockopt])
 
 Makefile.am:
 if GL_COND_OBJ_GETSOCKOPT
-- 
2.39.5