diff options
| author | Ihor Antonov <ihor@antonovs.family> | 2020-01-17 21:13:12 -0800 |
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2020-01-23 20:32:59 +0000 |
| commit | 8e2199644e4fc34ebf46ea65b7598517eaa69f18 (patch) | |
| tree | da60a6595452028ba59a68115d54a384e9e9bfdc /cursor | |
| parent | Remove unused HAVE_CONFIG_H define in meson (diff) | |
| download | wayland-8e2199644e4fc34ebf46ea65b7598517eaa69f18.tar wayland-8e2199644e4fc34ebf46ea65b7598517eaa69f18.tar.gz wayland-8e2199644e4fc34ebf46ea65b7598517eaa69f18.tar.bz2 wayland-8e2199644e4fc34ebf46ea65b7598517eaa69f18.tar.lz wayland-8e2199644e4fc34ebf46ea65b7598517eaa69f18.tar.xz wayland-8e2199644e4fc34ebf46ea65b7598517eaa69f18.tar.zst wayland-8e2199644e4fc34ebf46ea65b7598517eaa69f18.zip | |
os: fallback for unsupported posix_fallocate
Some filesystems do not support fallocate and return EOPNOTSUPP.
On musl-based distros libwayland-cursor exits abruptly which causes the
application to crash. Unlike glibc, musl does not provide a fallback
mechanism for handling unsupported fallocate. Instead, musl developers
argue that application should handle the case of unsupported system
call.
This commit allows falback to ftruncate in case when EOPNOTSUPP
was recieved.
Signed-off-by: Ihor Antonov <ihor@antonovs.family>
Diffstat (limited to 'cursor')
| -rw-r--r-- | cursor/os-compatibility.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/cursor/os-compatibility.c b/cursor/os-compatibility.c index 9008755..6f5b39f 100644 --- a/cursor/os-compatibility.c +++ b/cursor/os-compatibility.c @@ -156,19 +156,24 @@ os_create_anonymous_file(off_t size) } #ifdef HAVE_POSIX_FALLOCATE + /* + * Filesystems that do support fallocate will return EOPNOTSUPP. + * In this case we need to fall back to ftruncate + */ ret = posix_fallocate(fd, 0, size); - if (ret != 0) { + if (ret == 0) { + return fd; + } else if (ret != EOPNOTSUPP) { close(fd); errno = ret; return -1; } -#else +#endif ret = ftruncate(fd, size); if (ret < 0) { close(fd); return -1; } -#endif return fd; } |
