mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2025-10-29 05:40:16 -04:00
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>
This commit is contained in:
parent
501cad1188
commit
8e2199644e
1 changed files with 8 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue