mirror of
https://github.com/glfw/glfw.git
synced 2024-11-11 13:03:52 +00:00
wayland: Clean up anonymous file creation
It was a copy paste without fully updating the coding style. There were also some autotools macros that were no longer valid. So far its assumed that the needed functions exist. If better portability is needed, there needs to be some detction added to the cmake build script.
This commit is contained in:
parent
6e8e94837d
commit
cd51d285e6
@ -24,6 +24,8 @@
|
|||||||
//
|
//
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -101,43 +103,13 @@ static GLboolean createSurface(_GLFWwindow* window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
set_cloexec_or_close(int fd)
|
createTmpfileCloexec(char* tmpname)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef HAVE_MKOSTEMP
|
|
||||||
fd = mkostemp(tmpname, O_CLOEXEC);
|
fd = mkostemp(tmpname, O_CLOEXEC);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
unlink(tmpname);
|
unlink(tmpname);
|
||||||
#else
|
|
||||||
fd = mkstemp(tmpname);
|
|
||||||
if (fd >= 0) {
|
|
||||||
fd = set_cloexec_or_close(fd);
|
|
||||||
unlink(tmpname);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
@ -157,23 +129,23 @@ create_tmpfile_cloexec(char *tmpname)
|
|||||||
* transmitting the file descriptor over Unix sockets using the
|
* transmitting the file descriptor over Unix sockets using the
|
||||||
* SCM_RIGHTS methods.
|
* SCM_RIGHTS methods.
|
||||||
*
|
*
|
||||||
* If the C library implements posix_fallocate(), it is used to
|
* posix_fallocate() is used to guarantee that disk space is available
|
||||||
* guarantee that disk space is available for the file at the
|
* for the file at the given size. If disk space is insufficent, errno
|
||||||
* given size. If disk space is insufficent, errno is set to ENOSPC.
|
* is set to ENOSPC. If posix_fallocate() is not supported, program may
|
||||||
* If posix_fallocate() is not supported, program may receive
|
* receive SIGBUS on accessing mmap()'ed file contents instead.
|
||||||
* SIGBUS on accessing mmap()'ed file contents instead.
|
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
os_create_anonymous_file(off_t size)
|
createAnonymousFile(off_t size)
|
||||||
{
|
{
|
||||||
static const char template[] = "/glfw-shared-XXXXXX";
|
static const char template[] = "/glfw-shared-XXXXXX";
|
||||||
const char *path;
|
const char* path;
|
||||||
char *name;
|
char* name;
|
||||||
int fd;
|
int fd;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
path = getenv("XDG_RUNTIME_DIR");
|
path = getenv("XDG_RUNTIME_DIR");
|
||||||
if (!path) {
|
if (!path)
|
||||||
|
{
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -182,14 +154,15 @@ os_create_anonymous_file(off_t size)
|
|||||||
strcpy(name, path);
|
strcpy(name, path);
|
||||||
strcat(name, template);
|
strcat(name, template);
|
||||||
|
|
||||||
fd = create_tmpfile_cloexec(name);
|
fd = createTmpfileCloexec(name);
|
||||||
|
|
||||||
free(name);
|
free(name);
|
||||||
|
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return -1;
|
return -1;
|
||||||
ret = posix_fallocate(fd, 0, size);
|
ret = posix_fallocate(fd, 0, size);
|
||||||
if (ret != 0) {
|
if (ret != 0)
|
||||||
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
errno = ret;
|
errno = ret;
|
||||||
return -1;
|
return -1;
|
||||||
@ -403,7 +376,7 @@ int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
|
|||||||
void *data;
|
void *data;
|
||||||
int fd, i;
|
int fd, i;
|
||||||
|
|
||||||
fd = os_create_anonymous_file(length);
|
fd = createAnonymousFile(length);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
"Wayland: Creating a buffer file for %d B failed: %m\n",
|
"Wayland: Creating a buffer file for %d B failed: %m\n",
|
||||||
|
Loading…
Reference in New Issue
Block a user