diff options
| author | Jan Beich <jbeich@FreeBSD.org> | 2020-02-16 05:54:33 +0000 |
|---|---|---|
| committer | Jan Beich <jbeich@FreeBSD.org> | 2020-02-23 20:42:54 +0000 |
| commit | 230885ebb40b35c68a3b88a649f449afa344ec28 (patch) | |
| tree | c4db8de54ed52633731932e3f065292bf771ff62 /cursor | |
| parent | cursor: ignore posix_fallocate in shm_pool_resize if not supported by FS (diff) | |
| download | wayland-230885ebb40b35c68a3b88a649f449afa344ec28.tar wayland-230885ebb40b35c68a3b88a649f449afa344ec28.tar.gz wayland-230885ebb40b35c68a3b88a649f449afa344ec28.tar.bz2 wayland-230885ebb40b35c68a3b88a649f449afa344ec28.tar.lz wayland-230885ebb40b35c68a3b88a649f449afa344ec28.tar.xz wayland-230885ebb40b35c68a3b88a649f449afa344ec28.tar.zst wayland-230885ebb40b35c68a3b88a649f449afa344ec28.zip | |
cursor/os-compatibility: move resizing into a separate function
Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
Diffstat (limited to 'cursor')
| -rw-r--r-- | cursor/os-compatibility.c | 30 | ||||
| -rw-r--r-- | cursor/os-compatibility.h | 3 | ||||
| -rw-r--r-- | cursor/wayland-cursor.c | 12 |
3 files changed, 21 insertions, 24 deletions
diff --git a/cursor/os-compatibility.c b/cursor/os-compatibility.c index 002bb5c..9eac229 100644 --- a/cursor/os-compatibility.c +++ b/cursor/os-compatibility.c @@ -119,7 +119,6 @@ os_create_anonymous_file(off_t size) const char *path; char *name; int fd; - int ret; #ifdef HAVE_MEMFD_CREATE fd = memfd_create("wayland-cursor", MFD_CLOEXEC | MFD_ALLOW_SEALING); @@ -155,25 +154,30 @@ os_create_anonymous_file(off_t size) return -1; } + if (os_resize_anonymous_file(fd, size) < 0) { + close(fd); + return -1; + } + + return fd; +} + +int +os_resize_anonymous_file(int fd, off_t size) +{ #ifdef HAVE_POSIX_FALLOCATE /* * Filesystems that do support fallocate will return EINVAL or * EOPNOTSUPP. In this case we need to fall back to ftruncate */ - ret = posix_fallocate(fd, 0, size); - if (ret == 0) { - return fd; - } else if (ret != EINVAL && ret != EOPNOTSUPP) { - close(fd); - errno = ret; + errno = posix_fallocate(fd, 0, size); + if (errno == 0) + return 0; + else if (errno != EINVAL && errno != EOPNOTSUPP) return -1; - } #endif - ret = ftruncate(fd, size); - if (ret < 0) { - close(fd); + if (ftruncate(fd, size) < 0) return -1; - } - return fd; + return 0; } diff --git a/cursor/os-compatibility.h b/cursor/os-compatibility.h index d0e69ac..fdfeb78 100644 --- a/cursor/os-compatibility.h +++ b/cursor/os-compatibility.h @@ -31,4 +31,7 @@ int os_create_anonymous_file(off_t size); +int +os_resize_anonymous_file(int fd, off_t size); + #endif /* OS_COMPATIBILITY_H */ diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c index ca5be8d..4e2dc50 100644 --- a/cursor/wayland-cursor.c +++ b/cursor/wayland-cursor.c @@ -83,17 +83,7 @@ err_free: static int shm_pool_resize(struct shm_pool *pool, int size) { -#ifdef HAVE_POSIX_FALLOCATE - /* - * Filesystems that do support fallocate will return EINVAL or - * EOPNOTSUPP. In this case we need to fall back to ftruncate - */ - errno = posix_fallocate(pool->fd, 0, size); - if (errno != 0 && errno != EINVAL && errno != EOPNOTSUPP) - return 0; -#endif - - if (ftruncate(pool->fd, size) < 0) + if (os_resize_anonymous_file(pool->fd, size) < 0) return 0; wl_shm_pool_resize(pool->pool, size); |
