Put the libcursor os-compatibility stuff in wayland-os.c instead. Signed-off-by: Derek Foreman <der...@osg.samsung.com> --- Makefile.am | 4 +- cursor/os-compatibility.c | 127 ---------------------------------------------- cursor/os-compatibility.h | 34 ------------- cursor/wayland-cursor.c | 5 +- src/wayland-os.c | 93 +++++++++++++++++++++++++++++++++ src/wayland-os.h | 4 ++ 6 files changed, 101 insertions(+), 166 deletions(-) delete mode 100644 cursor/os-compatibility.c delete mode 100644 cursor/os-compatibility.h
diff --git a/Makefile.am b/Makefile.am index e850abc..f180c17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -124,9 +124,9 @@ lib_LTLIBRARIES += libwayland-cursor.la include_HEADERS += cursor/wayland-cursor.h libwayland_cursor_la_SOURCES = \ + src/wayland-os.c \ + src/wayland-os.h \ cursor/wayland-cursor.c \ - cursor/os-compatibility.c \ - cursor/os-compatibility.h \ cursor/cursor-data.h \ cursor/xcursor.c \ cursor/xcursor.h diff --git a/cursor/os-compatibility.c b/cursor/os-compatibility.c deleted file mode 100644 index 6883a1d..0000000 --- a/cursor/os-compatibility.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright © 2012 Collabora, Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#define _GNU_SOURCE - -#include <sys/types.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> - -#include "config.h" -#include "os-compatibility.h" - -static int -create_tmpfile_cloexec(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 = wl_os_set_cloexec_or_close(fd); - unlink(tmpname); - } -#endif - - return fd; -} - -/* - * Create a new, unique, anonymous file of the given size, and - * return the file descriptor for it. The file descriptor is set - * CLOEXEC. The file is immediately suitable for mmap()'ing - * the given size at offset zero. - * - * The file should not have a permanent backing store like a disk, - * but may have if XDG_RUNTIME_DIR is not properly implemented in OS. - * - * The file name is deleted from the file system. - * - * The file is suitable for buffer sharing between processes by - * 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. - */ -int -os_create_anonymous_file(off_t size) -{ - static const char template[] = "/weston-shared-XXXXXX"; - const char *path; - char *name; - int fd; - int ret; - - path = getenv("XDG_RUNTIME_DIR"); - if (!path) { - errno = ENOENT; - return -1; - } - - name = malloc(strlen(path) + sizeof(template)); - if (!name) - return -1; - - strcpy(name, path); - strcat(name, template); - - fd = create_tmpfile_cloexec(name); - - free(name); - - if (fd < 0) - return -1; - - if (!size) - return fd; - -#ifdef HAVE_POSIX_FALLOCATE - ret = posix_fallocate(fd, 0, size); - if (ret != 0) { - close(fd); - errno = ret; - return -1; - } -#else - ret = ftruncate(fd, size); - if (ret < 0) { - close(fd); - return -1; - } -#endif - - return fd; -} diff --git a/cursor/os-compatibility.h b/cursor/os-compatibility.h deleted file mode 100644 index d0e69ac..0000000 --- a/cursor/os-compatibility.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2012 Collabora, Ltd. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef OS_COMPATIBILITY_H -#define OS_COMPATIBILITY_H - -#include <sys/types.h> - -int -os_create_anonymous_file(off_t size); - -#endif /* OS_COMPATIBILITY_H */ diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c index 18abe87..7319812 100644 --- a/cursor/wayland-cursor.c +++ b/cursor/wayland-cursor.c @@ -27,6 +27,7 @@ #include "xcursor.h" #include "wayland-cursor.h" #include "wayland-client.h" +#include "wayland-os.h" #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -35,8 +36,6 @@ #include <fcntl.h> #include <errno.h> -#include "os-compatibility.h" - #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) struct shm_pool { @@ -56,7 +55,7 @@ shm_pool_create(struct wl_shm *shm, int size) if (!pool) return NULL; - pool->fd = os_create_anonymous_file(size); + pool->fd = wl_os_create_anonymous_file(size); if (pool->fd < 0) goto err_free; diff --git a/src/wayland-os.c b/src/wayland-os.c index 2cc87a1..40e63d7 100644 --- a/src/wayland-os.c +++ b/src/wayland-os.c @@ -25,6 +25,8 @@ #define _GNU_SOURCE +#include <string.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <unistd.h> @@ -165,3 +167,94 @@ wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen) fd = accept(sockfd, addr, addrlen); return wl_os_set_cloexec_or_close(fd); } + +static int +create_tmpfile_cloexec(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 = wl_os_set_cloexec_or_close(fd); + unlink(tmpname); + } +#endif + + return fd; +} + +/* + * Create a new, unique, anonymous file of the given size, and + * return the file descriptor for it. The file descriptor is set + * CLOEXEC. The file is immediately suitable for mmap()'ing + * the given size at offset zero. + * + * The file should not have a permanent backing store like a disk, + * but may have if XDG_RUNTIME_DIR is not properly implemented in OS. + * + * The file name is deleted from the file system. + * + * The file is suitable for buffer sharing between processes by + * 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. + */ +int +wl_os_create_anonymous_file(off_t size) +{ + static const char template[] = "/weston-shared-XXXXXX"; + const char *path; + char *name; + int fd; + int ret; + + path = getenv("XDG_RUNTIME_DIR"); + if (!path) { + errno = ENOENT; + return -1; + } + + name = malloc(strlen(path) + sizeof(template)); + if (!name) + return -1; + + strcpy(name, path); + strcat(name, template); + + fd = create_tmpfile_cloexec(name); + + free(name); + + if (fd < 0) + return -1; + + if (!size) + return fd; + +#ifdef HAVE_POSIX_FALLOCATE + ret = posix_fallocate(fd, 0, size); + if (ret != 0) { + close(fd); + errno = ret; + return -1; + } +#else + ret = ftruncate(fd, size); + if (ret < 0) { + close(fd); + return -1; + } +#endif + + return fd; +} diff --git a/src/wayland-os.h b/src/wayland-os.h index e756841..465a638 100644 --- a/src/wayland-os.h +++ b/src/wayland-os.h @@ -26,6 +26,8 @@ #ifndef WAYLAND_OS_H #define WAYLAND_OS_H +#include <sys/socket.h> + int wl_os_set_cloexec_or_close(int fd); @@ -44,6 +46,8 @@ wl_os_epoll_create_cloexec(void); int wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen); +int +wl_os_create_anonymous_file(off_t size); /* * The following are for wayland-os.c and the unit tests. -- 2.7.0 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel