From 1ce8b14f90a8e135f3260cc1f71d8b5f67432b3f Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Mon, 23 Sep 2024 17:52:43 +0200
Subject: [PATCH] getopt-posix: Fix compilation error in C++ mode (regression
 2024-09-21).

* lib/getopt-pfx-core.h: On AIX, HP-UX, Solaris, QNX, include <stdio.h>
first.
---
 ChangeLog             | 6 ++++++
 lib/getopt-pfx-core.h | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 15a6910355..8b822becc4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-09-23  Bruno Haible  <bruno@clisp.org>
+
+	getopt-posix: Fix compilation error in C++ mode (regression 2024-09-21).
+	* lib/getopt-pfx-core.h: On AIX, HP-UX, Solaris, QNX, include <stdio.h>
+	first.
+
 2024-09-21  Bruno Haible  <bruno@clisp.org>
 
 	getopt-posix, crypto/md5-buffer: Fix __GNUC_PREREQ re clang.
diff --git a/lib/getopt-pfx-core.h b/lib/getopt-pfx-core.h
index 78b7816aa4..df2cb183a5 100644
--- a/lib/getopt-pfx-core.h
+++ b/lib/getopt-pfx-core.h
@@ -31,6 +31,13 @@
    functions and variables.  Renaming avoids problems with some
    compilers and linkers.  */
 #ifdef __GETOPT_PREFIX
+
+/* Include platform-dependent header files that may declare getopt() and
+   friends.  */
+# if defined _AIX || defined __hpux || defined __sun || defined __QNX__
+#  include <stdio.h>
+# endif
+
 # ifndef __GETOPT_ID
 #  define __GETOPT_CONCAT(x, y) x ## y
 #  define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
-- 
2.39.5