]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fallocate: fix the way to evaluate values returned from posix_fallocate
authorMasatake YAMATO <yamato@redhat.com>
Fri, 19 Jan 2024 14:47:30 +0000 (23:47 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 19 Jan 2024 14:47:30 +0000 (23:47 +0900)
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 <yamato@redhat.com>
sys-utils/fallocate.c

index 19fb87ff79b3e77c9da32c109b214de472dbac6a..ac7c687f22f093a9b866f96d5cf4f16d6c518736 100644 (file)
@@ -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"));
        }
 }