Provide pipe2() and mkostemp() fallbacks for Darwin. Darwin has no pipe2() at all; mkostemp() appeared in macOS 10.12; O_CLOEXEC appeared in the 10.7 SDK. Emulate the exact subset the Wayland backend uses (O_CLOEXEC / O_NONBLOCK via fcntl). The private O_CLOEXEC value is only tested against by the shims themselves and never reaches the kernel. --- src/video/wayland/SDL_waylanddatamanager.c +++ src/video/wayland/SDL_waylanddatamanager.c @@ -37,6 +37,43 @@ #include "SDL_waylanddatamanager.h" #include "primary-selection-unstable-v1-client-protocol.h" +#ifdef SDL_PLATFORM_APPLE +/* Darwin has no pipe2(), and SDKs before Mac OS X 10.7 lack O_CLOEXEC. The + flags are only interpreted here and are never passed to the kernel. */ +#ifndef O_CLOEXEC +#define O_CLOEXEC 0x1000000 +#endif +static int Wayland_pipe2(int fds[2], int flags) +{ + int i; + + if (pipe(fds) == -1) { + return -1; + } + for (i = 0; i < 2; ++i) { + if (flags & O_CLOEXEC) { + if (fcntl(fds[i], F_SETFD, FD_CLOEXEC) == -1) { + goto error; + } + } + if (flags & O_NONBLOCK) { + const int fl = fcntl(fds[i], F_GETFL); + if (fl == -1 || fcntl(fds[i], F_SETFL, fl | O_NONBLOCK) == -1) { + goto error; + } + } + } + return 0; + +error: + close(fds[0]); + close(fds[1]); + fds[0] = fds[1] = -1; + return -1; +} +#define pipe2 Wayland_pipe2 +#endif // SDL_PLATFORM_APPLE + /* This is arbitrary, but reading while polling should block for less than a frame, to * prevent hanging while pumping events. * --- src/video/wayland/SDL_waylandshmbuffer.c +++ src/video/wayland/SDL_waylandshmbuffer.c @@ -33,6 +33,29 @@ #include "SDL_waylandshmbuffer.h" #include "SDL_waylandvideo.h" +#ifdef SDL_PLATFORM_APPLE +/* Darwin gained mkostemp() only in macOS 10.12, and SDKs before Mac OS X + 10.7 lack O_CLOEXEC. The flag is only interpreted here and is never + passed to the kernel. */ +#ifndef O_CLOEXEC +#define O_CLOEXEC 0x1000000 +#endif +static int Wayland_mkostemp(char *tmpl, int flags) +{ + const int fd = mkstemp(tmpl); + + if (fd >= 0 && (flags & O_CLOEXEC)) { + if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { + close(fd); + unlink(tmpl); + return -1; + } + } + return fd; +} +#define mkostemp Wayland_mkostemp +#endif // SDL_PLATFORM_APPLE + static bool SetTempFileSize(int fd, off_t size) { #ifdef HAVE_POSIX_FALLOCATE