diff --git a/src/wl_window.c b/src/wl_window.c index 64a83d16..3407370a 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -24,6 +24,8 @@ // //======================================================================== +#define _GNU_SOURCE + #include "internal.h" #include @@ -101,43 +103,13 @@ static GLboolean createSurface(_GLFWwindow* window, } static int -set_cloexec_or_close(int fd) -{ - long flags; - - if (fd == -1) - return -1; - - flags = fcntl(fd, F_GETFD); - if (flags == -1) - goto err; - - if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) - goto err; - - return fd; - -err: - close(fd); - return -1; -} - -static int -create_tmpfile_cloexec(char *tmpname) +createTmpfileCloexec(char* tmpname) { int fd; -#ifdef HAVE_MKOSTEMP fd = mkostemp(tmpname, O_CLOEXEC); if (fd >= 0) unlink(tmpname); -#else - fd = mkstemp(tmpname); - if (fd >= 0) { - fd = set_cloexec_or_close(fd); - unlink(tmpname); - } -#endif return fd; } @@ -157,23 +129,23 @@ create_tmpfile_cloexec(char *tmpname) * transmitting the file descriptor over Unix sockets using the * SCM_RIGHTS methods. * - * If the C library implements posix_fallocate(), it is used to - * guarantee that disk space is available for the file at the - * given size. If disk space is insufficent, errno is set to ENOSPC. - * If posix_fallocate() is not supported, program may receive - * SIGBUS on accessing mmap()'ed file contents instead. + * posix_fallocate() is used to guarantee that disk space is available + * for the file at the given size. If disk space is insufficent, errno + * is set to ENOSPC. If posix_fallocate() is not supported, program may + * receive SIGBUS on accessing mmap()'ed file contents instead. */ int -os_create_anonymous_file(off_t size) +createAnonymousFile(off_t size) { static const char template[] = "/glfw-shared-XXXXXX"; - const char *path; - char *name; + const char* path; + char* name; int fd; int ret; path = getenv("XDG_RUNTIME_DIR"); - if (!path) { + if (!path) + { errno = ENOENT; return -1; } @@ -182,14 +154,15 @@ os_create_anonymous_file(off_t size) strcpy(name, path); strcat(name, template); - fd = create_tmpfile_cloexec(name); + fd = createTmpfileCloexec(name); free(name); if (fd < 0) return -1; ret = posix_fallocate(fd, 0, size); - if (ret != 0) { + if (ret != 0) + { close(fd); errno = ret; return -1; @@ -403,7 +376,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor, void *data; int fd, i; - fd = os_create_anonymous_file(length); + fd = createAnonymousFile(length); if (fd < 0) { _glfwInputError(GLFW_PLATFORM_ERROR, "Wayland: Creating a buffer file for %d B failed: %m\n",