Codebase list wayland / a29d17e
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> Ihor Antonov authored 4 years ago Héctor Orón Martínez committed 4 years ago
1 changed file(s) with 8 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
155155 }
156156
157157 #ifdef HAVE_POSIX_FALLOCATE
158 /*
159 * Filesystems that do support fallocate will return EOPNOTSUPP.
160 * In this case we need to fall back to ftruncate
161 */
158162 ret = posix_fallocate(fd, 0, size);
159 if (ret != 0) {
163 if (ret == 0) {
164 return fd;
165 } else if (ret != EOPNOTSUPP) {
160166 close(fd);
161167 errno = ret;
162168 return -1;
163169 }
164 #else
170 #endif
165171 ret = ftruncate(fd, size);
166172 if (ret < 0) {
167173 close(fd);
168174 return -1;
169175 }
170 #endif
171176
172177 return fd;
173178 }