mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
cursor/os-compatibility: move resizing into a separate function
Signed-off-by: Jan Beich <jbeich@FreeBSD.org>
This commit is contained in:
parent
3a3dd0820d
commit
230885ebb4
3 changed files with 25 additions and 28 deletions
|
|
@ -119,7 +119,6 @@ os_create_anonymous_file(off_t size)
|
||||||
const char *path;
|
const char *path;
|
||||||
char *name;
|
char *name;
|
||||||
int fd;
|
int fd;
|
||||||
int ret;
|
|
||||||
|
|
||||||
#ifdef HAVE_MEMFD_CREATE
|
#ifdef HAVE_MEMFD_CREATE
|
||||||
fd = memfd_create("wayland-cursor", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
fd = memfd_create("wayland-cursor", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
||||||
|
|
@ -155,25 +154,30 @@ os_create_anonymous_file(off_t size)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_POSIX_FALLOCATE
|
if (os_resize_anonymous_file(fd, size) < 0) {
|
||||||
/*
|
|
||||||
* 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;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
ret = ftruncate(fd, size);
|
|
||||||
if (ret < 0) {
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
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
|
||||||
|
*/
|
||||||
|
errno = posix_fallocate(fd, 0, size);
|
||||||
|
if (errno == 0)
|
||||||
|
return 0;
|
||||||
|
else if (errno != EINVAL && errno != EOPNOTSUPP)
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
if (ftruncate(fd, size) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,7 @@
|
||||||
int
|
int
|
||||||
os_create_anonymous_file(off_t size);
|
os_create_anonymous_file(off_t size);
|
||||||
|
|
||||||
|
int
|
||||||
|
os_resize_anonymous_file(int fd, off_t size);
|
||||||
|
|
||||||
#endif /* OS_COMPATIBILITY_H */
|
#endif /* OS_COMPATIBILITY_H */
|
||||||
|
|
|
||||||
|
|
@ -83,17 +83,7 @@ err_free:
|
||||||
static int
|
static int
|
||||||
shm_pool_resize(struct shm_pool *pool, int size)
|
shm_pool_resize(struct shm_pool *pool, int size)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_POSIX_FALLOCATE
|
if (os_resize_anonymous_file(pool->fd, size) < 0)
|
||||||
/*
|
|
||||||
* 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)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
wl_shm_pool_resize(pool->pool, size);
|
wl_shm_pool_resize(pool->pool, size);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue