From 35e57a543a28a79f26d2970b2c19be6b73c6d1da Mon Sep 17 00:00:00 2001
From: Chase <chinkle3@illinois.edu>
Date: Fri, 28 Nov 2025 14:05:59 -0500
Subject: [PATCH] Feature test for poll.h

---
 cde/configure.ac                               |  2 +-
 cde/lib/csa/agent.c                            |  7 ++++++-
 cde/lib/tt/bin/tttrace/tttrace.C               |  7 +++++--
 cde/lib/tt/lib/mp/mp_stream_socket.C           |  7 +++++--
 cde/lib/tt/lib/tttk/tttk.C                     |  7 +++++--
 cde/lib/tt/lib/util/tt_file_system.C           |  8 +++++---
 cde/programs/dtmail/libDtMail/Common/Process.C |  7 +++++++
 cde/programs/dtmail/libDtMail/RFC/SunV3.C      |  7 +++++++
 cde/programs/dtscreen/dtscreen.h               | 12 ++++++++++--
 9 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/cde/configure.ac b/cde/configure.ac
index 48e6b32cd..67a7dd006 100644
--- a/cde/configure.ac
+++ b/cde/configure.ac
@@ -445,7 +445,7 @@ dnl Used to check if program 'tic' is available to install terminfo files
 AC_CHECK_PROGS(TIC, tic, :)
 
 dnl headers
-AC_CHECK_HEADERS([locale.h security/pam_appl.h utempter.h])
+AC_CHECK_HEADERS([locale.h poll.h sys/poll.h security/pam_appl.h utempter.h])
 
 dnl Xrender header
 AC_CHECK_HEADERS([X11/extensions/Xrender.h], [],
diff --git a/cde/lib/csa/agent.c b/cde/lib/csa/agent.c
index 4b110bae5..2146e6c76 100644
--- a/cde/lib/csa/agent.c
+++ b/cde/lib/csa/agent.c
@@ -28,14 +28,19 @@
  *  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  */
 
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
 #include <EUSCompat.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
 #include <rpc/rpc.h>
-#if !defined(__linux__) && !defined(CSRG_BASED)
+#if HAVE_POLL_H
 # include <poll.h>
+#elif HAVE_SYS_POLL_H
+# include <sys/poll.h>
 #endif
 #if defined(SunOS)
 #include <netconfig.h>
diff --git a/cde/lib/tt/bin/tttrace/tttrace.C b/cde/lib/tt/bin/tttrace/tttrace.C
index 8012996ad..243d45521 100644
--- a/cde/lib/tt/bin/tttrace/tttrace.C
+++ b/cde/lib/tt/bin/tttrace/tttrace.C
@@ -31,6 +31,9 @@
  * Copyright (c) 1993 by Sun Microsystems, Inc.
  */
 
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -38,9 +41,9 @@
 #include <string.h>
 #include <unistd.h>
 #include <signal.h>
-#if defined(__linux__)
+#if HAVE_SYS_POLL_H
 # include <sys/poll.h>
-#else
+#elif HAVE_POLL_H
 # include <poll.h>
 #endif
 #include <sys/types.h>
diff --git a/cde/lib/tt/lib/mp/mp_stream_socket.C b/cde/lib/tt/lib/mp/mp_stream_socket.C
index 5009a99ef..3e034fbfe 100644
--- a/cde/lib/tt/lib/mp/mp_stream_socket.C
+++ b/cde/lib/tt/lib/mp/mp_stream_socket.C
@@ -31,12 +31,15 @@
  *
  * Copyright (c) 1990 by Sun Microsystems, Inc.
  */
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
 #include "tt_options.h"
 #include <stdio.h>
 #include "mp/mp_stream_socket.h"
-#if defined(__linux__)
+#if HAVE_SYS_POLL_H
 #include <sys/poll.h>
-#else
+#elif HAVE_POLL_H
 #include <poll.h>
 #endif
 #include <sys/socket.h>
diff --git a/cde/lib/tt/lib/tttk/tttk.C b/cde/lib/tt/lib/tttk/tttk.C
index 826ec8b9e..e351d6a57 100644
--- a/cde/lib/tt/lib/tttk/tttk.C
+++ b/cde/lib/tt/lib/tttk/tttk.C
@@ -25,9 +25,12 @@
 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.			
 //%%  (c) Copyright 1993, 1994 Novell, Inc. 				
 //%%  $TOG: tttk.C /main/5 1999/09/14 13:00:44 mgreess $ 			 				
-#if defined(__linux__)
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
+#if HAVE_SYS_POLL_H
 # include <sys/poll.h>
-#else
+#elif HAVE_POLL_H
 # include <poll.h>
 #endif
 #include <errno.h>
diff --git a/cde/lib/tt/lib/util/tt_file_system.C b/cde/lib/tt/lib/util/tt_file_system.C
index 7973315cb..4cab26ed4 100644
--- a/cde/lib/tt/lib/util/tt_file_system.C
+++ b/cde/lib/tt/lib/util/tt_file_system.C
@@ -43,13 +43,15 @@
  * Defines a class for browsing the file system mount table.
  *
  */
-
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
-#if defined(__linux__)
+#if HAVE_SYS_POLL_H
 # include <sys/poll.h>
-#else
+#elif HAVE_POLL_H
 # include <poll.h>
 #endif
 #include <sys/stat.h>
diff --git a/cde/programs/dtmail/libDtMail/Common/Process.C b/cde/programs/dtmail/libDtMail/Common/Process.C
index 56611bb7a..4524c23e0 100644
--- a/cde/programs/dtmail/libDtMail/Common/Process.C
+++ b/cde/programs/dtmail/libDtMail/Common/Process.C
@@ -41,12 +41,19 @@
  *+ENOTICE
  */
 
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
+#if HAVE_POLL_H
 #include <poll.h>
+#elif HAVE_SYS_POLL_H
+#include <sys/poll.h>
+#endif
 
 /*
 ** file included for INFTIM
diff --git a/cde/programs/dtmail/libDtMail/RFC/SunV3.C b/cde/programs/dtmail/libDtMail/RFC/SunV3.C
index 8353b7a92..8ba942a75 100644
--- a/cde/programs/dtmail/libDtMail/RFC/SunV3.C
+++ b/cde/programs/dtmail/libDtMail/RFC/SunV3.C
@@ -40,13 +40,20 @@
  *+ENOTICE
  */
 
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
 #include <EUSCompat.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#if HAVE_POLL_H
 #include <poll.h>
+#elif HAVE_SYS_POLL_H
+#include <sys/poll.h>
+#endif
 #include <fcntl.h>
 #include <assert.h>
 #include <signal.h>
diff --git a/cde/programs/dtscreen/dtscreen.h b/cde/programs/dtscreen/dtscreen.h
index 4c7b4cce9..7f80759d9 100644
--- a/cde/programs/dtscreen/dtscreen.h
+++ b/cde/programs/dtscreen/dtscreen.h
@@ -87,15 +87,24 @@ extern void unhide_hft_ring();
 
 /* System V Release 4 redefinitions of BSD functions and structures */
 
+#if HAVE_CONFIG_H
+#include <cde_config.h>
+#endif
+
 #if defined (SYSV) || defined (SVR4)
 
+#if HAVE_SYS_POLL_H
+#include <sys/poll.h>
+#elif HAVE_POLL_H
+#include <poll.h>
+#endif
+
 #include <sys/time.h>
 #define passwd spwd
 #define pw_passwd sp_pwdp
 #if defined(AIXV3)
 #undef NULL
 #define NULL 0
-#include <sys/poll.h>
 
 struct passwd {
         char    *pw_name;
@@ -107,7 +116,6 @@ struct passwd {
         char    *pw_shell;
 };
 #else
-#include <poll.h>
 #include <shadow.h>
 #define getpwnam getspnam
 #endif
