From fa738e31cdc8b678c20c0c42d7432927db2640c2 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Fri, 19 Jan 2024 23:47:30 +0900 Subject: [PATCH] fallocate: fix the way to evaluate values returned from posix_fallocate Unlike Linux native system calls, posix_fallocate doesn't return -1 whe an error occurs; it returns a errno value directly. The bug of the original code was reported by @Yugend on #2714. Signed-off-by: Masatake YAMATO --- sys-utils/fallocate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index 19fb87ff79..ac7c687f22 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -144,8 +144,8 @@ static void xfallocate(int fd, int mode, off_t offset, off_t length) #ifdef HAVE_POSIX_FALLOCATE static void xposix_fallocate(int fd, off_t offset, off_t length) { - int error = posix_fallocate(fd, offset, length); - if (error < 0) { + errno = posix_fallocate(fd, offset, length); + if (errno != 0) { err(EXIT_FAILURE, _("fallocate failed")); } } -- 2.47.3