From 55c7acb51d1ae45f43206e45c2a10dc6bb48755d Mon Sep 17 00:00:00 2001
From: Aditya Kamath <Aditya.Kamath1@ibm.com>
Date: Tue, 3 Mar 2026 09:38:53 -0600
Subject: [PATCH v1 3/3] Fix compilation issues for test cases in AIX.

In AIX, IP_TOS, IP_RECVTOS and DSCP are all not defined. This patch is to fix the same.

The error we get otherwise are:

=========================== 1 ==============================================
FAILED: glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o
gcc -Iglib/tests/getpwuid-preload.so.p -Iglib/tests -I../glib/tests -I. -I.. -Iglib -I../glib -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -std=gnu99 -O2 -g -D_GNU_SOURCE -fno-strict-aliasing -DG_ENABLE_DEBUG -Wduplicated-branches -Wfloat-conversion -Wimplicit-fallthrough -Wmisleading-indentation -Wmissing-field-initializers -Wnonnull -Wnull-dereference -Wunused -Wno-unused-parameter -Wno-cast-function-type -Wno-pedantic -Wno-format-zero-length -Wno-variadic-macros -Werror=format=2 -Werror=init-self -Werror=missing-include-dirs -Werror=pointer-arith -Werror=unused-result -Wstrict-prototypes -Wno-bad-function-cast -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=pointer-sign -maix64 -O2 -fsigned-char -mcmodel=large -maix64 -O2 -fsigned-char -fPIC -MD -MQ glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o -MF glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o.d -o glib/tests/getpwuid-preload.so.p/getpwuid-preload.c.o -c ../glib/tests/getpwuid-preload.c
../glib/tests/getpwuid-preload.c:85:22: error: conflicting types for 'getpwnam_r'; have 'int(const char *, struct passwd *, char *, size_t,  struct passwd **)' {aka 'int(const char *, struct passwd *, char *, long unsigned int,  struct passwd **)'}
   85 | DEFINE_WRAPPER (int, getpwnam_r, (const char     *name,
      |                      ^~~~~~~~~~
../glib/tests/getpwuid-preload.c:37:15: note: in definition of macro 'DEFINE_WRAPPER'
   37 |   return_type func argument_list
      |               ^~~~
In file included from ../glib/tests/getpwuid-preload.c:25:
/usr/include/pwd.h:131:20: note: previous definition of 'getpwnam_r' with type 'int(const char *, struct passwd *, char *, int,  struct passwd **)'
  131 |         static int getpwnam_r(const char *__fptr, struct passwd *__gptr,
      |                    ^~~~~~~~~~
../glib/tests/getpwuid-preload.c:99:22: error: conflicting types for 'getpwuid_r'; have 'int(uid_t,  struct passwd * restrict,  char *, size_t,  struct passwd **)' {aka 'int(unsigned int,  struct passwd * restrict,  char *, long unsigned int,  struct passwd **)'}
   99 | DEFINE_WRAPPER (int, getpwuid_r, (uid_t           uid,
      |                      ^~~~~~~~~~
../glib/tests/getpwuid-preload.c:37:15: note: in definition of macro 'DEFINE_WRAPPER'
   37 |   return_type func argument_list
      |               ^~~~
/usr/include/pwd.h:124:20: note: previous definition of 'getpwuid_r' with type 'int(uid_t,  struct passwd *, char *, int,  struct passwd **)' {aka 'int(unsigned int,  struct passwd *, char *, int,  struct passwd **)'}
  124 |         static int getpwuid_r(uid_t __aptr, struct passwd *__bptr, char *__cptr,
      |                    ^~~~~~~~~~

==================== 2 ================================
DGLIB_COMPILE_SCHEMAS="/home/buildusr/jenkins/workspace/glib2/glib/_build/gio/glib-compile-schemas"' -UG_DISABLE_ASSERT -MD -MQ gio/tests/iptosmessage.p/iptosmessage.c.o -MF gio/tests/iptosmessage.p/iptosmessage.c.o.d -o gio/tests/iptosmessage.p/iptosmessage.c.o -c ../gio/tests/iptosmessage.c
../gio/tests/iptosmessage.c: In function 'send_recv_control_message':
../gio/tests/iptosmessage.c:70:47: error: 'IP_RECVTOS' undeclared (first use in this function); did you mean 'IP_RECVTTL'?
   70 |       g_socket_set_option (rsock, IPPROTO_IP, IP_RECVTOS, 1, &error);

==================== 3 ================================
-UG_DISABLE_ASSERT -Werror=sign-conversion -MD -MQ glib/tests/testing.p/testing.c.o -MF glib/tests/testing.p/testing.c.o.d -o glib/tests/testing.p/testing.c.o -c ../glib/tests/testing.c
../glib/tests/testing.c: In function 'test_subprocess_stdin':
../glib/tests/testing.c:470:39: error: 'F_DUPFD_CLOEXEC' undeclared (first use in this function); did you mean 'FD_CLOEXEC'?
  470 |   old_stdin_fd = fcntl (STDIN_FILENO, F_DUPFD_CLOEXEC, 0);
      |                                       ^~~~~~~~~~~~~~~
      |                                       FD_CLOEXEC

---
 gio/tests/iptosmessage.c      | 6 +++++-
 glib/tests/getpwuid-preload.c | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/gio/tests/iptosmessage.c b/gio/tests/iptosmessage.c
index 3c9ff20d1..bd4a0ad88 100644
--- a/gio/tests/iptosmessage.c
+++ b/gio/tests/iptosmessage.c
@@ -24,7 +24,7 @@
 #include <gio/giptosmessage.h>
 #include <gio/gnetworking.h>
 
-#if ! (defined(G_OS_WIN32) || defined(__APPLE__))
+#if ! (defined(G_OS_WIN32) || defined(__APPLE__) || defined(_AIX))
 
 static GSocketControlMessage *
 send_recv_control_message (GSocketFamily family, GSocketControlMessage *msg)
@@ -112,6 +112,8 @@ test_ip_tos (void)
   g_test_skip ("GSocketControlMessage not supported on Windows.");
 #elif defined(__APPLE__)
   g_test_skip ("IP_TOS not supported on macOS.");
+#elif defined(_AIX)
+  g_test_skip ("IP_TOS not supported on AIX.");
 #else
   GIPTosMessage *smsg;
   GIPTosMessage *rmsg;
@@ -134,6 +136,8 @@ test_ipv6_tclass (void)
   g_test_skip ("GSocketControlMessage not supported on Windows.");
 #elif defined(__APPLE__)
   g_test_skip ("IPV6_TCLASS not supported on macOS.");
+#elif defined(_AIX)
+  g_test_skip ("IPV6_TCLASS not supported on AIX.");
 #else
   GIPv6TclassMessage *smsg;
   GIPv6TclassMessage *rmsg;
diff --git a/glib/tests/getpwuid-preload.c b/glib/tests/getpwuid-preload.c
index 6b7a474af..a7a754178 100644
--- a/glib/tests/getpwuid-preload.c
+++ b/glib/tests/getpwuid-preload.c
@@ -70,6 +70,7 @@ should_modify_result (void)
   return (path != NULL && *path != '\0');
 }
 
+#ifndef _AIX
 static struct passwd my_pw;
 
 DEFINE_WRAPPER (struct passwd *, getpwuid, (uid_t uid))
@@ -107,4 +108,6 @@ DEFINE_WRAPPER (int, getpwuid_r, (uid_t           uid,
     pwd->pw_name = NULL;
   return code;
 }
+
+#endif
 #endif
-- 
2.51.2

--- ./glib/tests/testing.c_orig	2026-03-05 23:48:48.727722628 -0600
+++ ./glib/tests/testing.c	2026-03-05 23:50:39.949272383 -0600
@@ -447,7 +447,9 @@
 static void
 test_subprocess_stdin (void)
 {
-#ifdef G_OS_UNIX
+#ifdef _AIX
+  g_test_skip ("Testing stdin for subprocesses caanot be done on AIX at the moment");
+#elif G_OS_UNIX
   int old_stdin_fd = -1;
   int pipe_fd[2] = { -1, -1 };
   const char *test_string = "*hello there*";
