Check for O_CLOEXEC definition in fcntl.h at configuration time, If not available, define it internally as 0 (in SDL_internal.h). Define it as available for macOS >= 10.7 in SDL_config_macosx.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0bc157..9411c76 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -993,6 +993,10 @@ if(UNIX OR APPLE)
endif()
endif()
+if(UNIX OR APPLE OR HAIKU OR RISCOS)
+ CheckO_CLOEXEC()
+endif()
+
if(SDL_JOYSTICK)
if(SDL_VIRTUAL_JOYSTICK)
set(HAVE_VIRTUAL_JOYSTICK TRUE)
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 4b1a6e0..32be19c 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -53,6 +53,14 @@ macro(CheckDLOPEN)
endif()
endmacro()
+macro(CheckO_CLOEXEC)
+ check_c_source_compiles("
+ #include <fcntl.h>
+ int flag = O_CLOEXEC;
+ int main(void) {
+ }" HAVE_O_CLOEXEC)
+endmacro()
+
# Requires:
# - n/a
macro(CheckOSS)
diff --git a/configure b/configure
index 4f61328..cbd5782 100755
--- a/configure
+++ b/configure
@@ -20233,8 +20233,7 @@ int
main ()
{
- EGL_DISPMANX_WINDOW_T window;
-
+ EGL_DISPMANX_WINDOW_T window;
bcm_host_init();
;
@@ -24362,6 +24361,39 @@ $as_echo "#define SDL_LOADSO_DLOPEN 1" >>confdefs.h
fi
}
+CheckO_CLOEXEC()
+{
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for O_CLOEXEC" >&5
+$as_echo_n "checking for O_CLOEXEC... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+#include <fcntl.h>
+int flag = O_CLOEXEC;
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+ have_o_cloexec=yes
+else
+ have_o_cloexec=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_o_cloexec" >&5
+$as_echo "$have_o_cloexec" >&6; }
+ if test $have_o_cloexec = yes; then
+
+$as_echo "#define HAVE_O_CLOEXEC 1" >>confdefs.h
+
+ fi
+}
+
CheckUSBHID()
{
case "$host" in
@@ -25055,6 +25087,7 @@ $as_echo "#define SDL_VIDEO_DRIVER_ANDROID 1" >>confdefs.h
CheckDLOPEN
CheckARM
CheckNEON
+ CheckO_CLOEXEC
CheckOSS
CheckALSA
CheckPipewire
@@ -25321,10 +25354,8 @@ $as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
# Set up the core platform files
SOURCES="$SOURCES $srcdir/src/core/windows/*.c"
-
SOURCES="$SOURCES $srcdir/src/misc/windows/*.c"
have_misc=yes
-
# Use the Windows locale APIs.
SOURCES="$SOURCES $srcdir/src/locale/windows/*.c"
have_locale=yes
@@ -25556,6 +25587,7 @@ fi
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckHaikuVideo
CheckHaikuGL
CheckPTHREAD
@@ -25623,6 +25655,7 @@ $as_echo "#define SDL_FILESYSTEM_HAIKU 1" >>confdefs.h
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckMETAL
CheckVulkan
CheckPTHREAD
@@ -25749,6 +25782,7 @@ $as_echo "#define SDL_VIDEO_RENDER_OGL_ES2 1" >>confdefs.h
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckCOCOA
CheckMETAL
CheckX11
@@ -25845,6 +25879,7 @@ $as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
CheckOffscreenVideo
CheckInputEvents
CheckPTHREAD
+ CheckO_CLOEXEC
# Set up files for the timer library
if test x$enable_timers = xyes; then
@@ -25940,6 +25975,7 @@ $as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckOSS
CheckPTHREAD
CheckClockGettime
diff --git a/configure.ac b/configure.ac
index 2cc063a..625681a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1701,8 +1701,7 @@ CheckRPI()
#include <bcm_host.h>
#include <EGL/eglplatform.h>
]], [[
- EGL_DISPMANX_WINDOW_T window;
-
+ EGL_DISPMANX_WINDOW_T window;
bcm_host_init();
]])], [have_video_rpi=yes],[])
AC_MSG_RESULT($have_video_rpi)
@@ -3296,6 +3295,19 @@ CheckDLOPEN()
fi
}
+CheckO_CLOEXEC()
+{
+ AC_MSG_CHECKING(for O_CLOEXEC)
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <fcntl.h>
+int flag = O_CLOEXEC;
+ ]],[])], [have_o_cloexec=yes],[have_o_cloexec=no])
+ AC_MSG_RESULT($have_o_cloexec)
+ if test $have_o_cloexec = yes; then
+ AC_DEFINE(HAVE_O_CLOEXEC, 1, [ ])
+ fi
+}
+
dnl Check for the usbhid(3) library on *BSD
CheckUSBHID()
{
@@ -3630,6 +3642,7 @@ case "$host" in
CheckDLOPEN
CheckARM
CheckNEON
+ CheckO_CLOEXEC
CheckOSS
CheckALSA
CheckPipewire
@@ -3862,10 +3875,8 @@ case "$host" in
# Set up the core platform files
SOURCES="$SOURCES $srcdir/src/core/windows/*.c"
-
SOURCES="$SOURCES $srcdir/src/misc/windows/*.c"
have_misc=yes
-
# Use the Windows locale APIs.
SOURCES="$SOURCES $srcdir/src/locale/windows/*.c"
have_locale=yes
@@ -4014,6 +4025,7 @@ case "$host" in
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckHaikuVideo
CheckHaikuGL
CheckPTHREAD
@@ -4071,6 +4083,7 @@ case "$host" in
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckMETAL
CheckVulkan
CheckPTHREAD
@@ -4175,6 +4188,7 @@ case "$host" in
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckCOCOA
CheckMETAL
CheckX11
@@ -4259,6 +4273,7 @@ case "$host" in
CheckOffscreenVideo
CheckInputEvents
CheckPTHREAD
+ CheckO_CLOEXEC
# Set up files for the timer library
if test x$enable_timers = xyes; then
@@ -4338,6 +4353,7 @@ case "$host" in
CheckDiskAudio
CheckDummyAudio
CheckDLOPEN
+ CheckO_CLOEXEC
CheckOSS
CheckPTHREAD
CheckClockGettime
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 46b404e..3865581 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -222,6 +222,7 @@
#cmakedefine HAVE_INOTIFY_INIT 1
#cmakedefine HAVE_INOTIFY_INIT1 1
#cmakedefine HAVE_INOTIFY 1
+#cmakedefine HAVE_O_CLOEXEC 1
/* Apple platforms might be building universal binaries, where Intel builds
can use immintrin.h but other architectures can't. */
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index ddab098..9073cea 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -215,6 +215,7 @@
#define HAVE_STDINT_H 1
#endif /* HAVE_LIBC */
+#undef HAVE_O_CLOEXEC
#undef HAVE_ALTIVEC_H
#undef HAVE_DBUS_DBUS_H
#undef HAVE_FCITX
@@ -234,14 +235,13 @@
#undef HAVE_DXGI_H
#undef HAVE_WINDOWS_GAMING_INPUT_H
#undef HAVE_XINPUT_H
+#undef HAVE_XINPUT_GAMEPAD_EX
+#undef HAVE_XINPUT_STATE_EX
#undef HAVE_MMDEVICEAPI_H
#undef HAVE_AUDIOCLIENT_H
#undef HAVE_SENSORSAPI_H
-#undef HAVE_XINPUT_GAMEPAD_EX
-#undef HAVE_XINPUT_STATE_EX
-
/* SDL internal assertion support */
#undef SDL_DEFAULT_ASSERT_LEVEL
diff --git a/include/SDL_config_macosx.h b/include/SDL_config_macosx.h
index 40c7206..2a59959 100644
--- a/include/SDL_config_macosx.h
+++ b/include/SDL_config_macosx.h
@@ -144,6 +144,10 @@
# endif
#endif
+#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070)
+#define HAVE_O_CLOEXEC 1
+#endif
+
#define HAVE_GCC_ATOMICS 1
/* Enable various audio drivers */
diff --git a/src/SDL_internal.h b/src/SDL_internal.h
index 660c247..c06a477 100644
--- a/src/SDL_internal.h
+++ b/src/SDL_internal.h
@@ -51,6 +51,10 @@
#include "SDL_config.h"
+#ifndef HAVE_O_CLOEXEC
+#define O_CLOEXEC 0
+#endif
+
/* A few #defines to reduce SDL2 footprint.
Only effective when library is statically linked.
You have to manually edit this file. */