const char *path;
char *name;
int fd;
- int ret;
#ifdef HAVE_MEMFD_CREATE
fd = memfd_create("wayland-cursor", MFD_CLOEXEC | MFD_ALLOW_SEALING);
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;
}
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);