summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux
diff options
context:
space:
mode:
authorYuriy Kolerov <yuriy.kolerov@synopsys.com>2015-09-23 15:43:37 +0300
committerWaldemar Brodkorb <wbx@openadk.org>2015-10-05 22:07:08 +0200
commit2eb8070e678937e7e7835d167cffb11628b8862e (patch)
tree295e81dff6fc1bd713b9e7a90fb9992043b7c1f6 /libc/sysdeps/linux
parent39e50d004f9b2cfd0988f670a877d83ee17d2418 (diff)
libc: fix setting return value and errno in fallocate()
fallocate system call must return 0 on success. On error, -1 is returned and errno is set to indicate the error. However there is an error in fallocate which is fixed by this patch - it does not set errno and returns invalid value on error (it returns error code instead of -1). This error is detected in LTP's test kernel/syscalls/fallocate02: ----------->8---------- fallocate(..., 1, 0, 1024) failed, expected errno:9: TEST_ERRNO=0 fallocate(..., 1, -1024, 1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 1024, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 12288, 0) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 12288, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, -24576, 1024) failed, expected errno:22: TEST_ERRNO=0 ----------->8---------- Signed-off-by: Yuriy Kolerov <yuriy.kolerov@synopsys.com>
Diffstat (limited to 'libc/sysdeps/linux')
-rw-r--r--libc/sysdeps/linux/common/fallocate.c9
-rw-r--r--libc/sysdeps/linux/common/fallocate64.c9
2 files changed, 12 insertions, 6 deletions
diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c
index b23122669..b2309e978 100644
--- a/libc/sysdeps/linux/common/fallocate.c
+++ b/libc/sysdeps/linux/common/fallocate.c
@@ -12,6 +12,7 @@
#include <fcntl.h>
#include <bits/kernel-features.h>
#include <stdint.h>
+#include <errno.h>
#if defined __NR_fallocate
extern __typeof(fallocate) __libc_fallocate attribute_hidden;
@@ -34,9 +35,11 @@ int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t
# else
# error your machine is neither 32 bit or 64 bit ... it must be magical
# endif
- if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
- return INTERNAL_SYSCALL_ERRNO (ret, err);
- return 0;
+ if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
+ __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
+ ret = -1;
+ }
+ return ret;
}
# if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
diff --git a/libc/sysdeps/linux/common/fallocate64.c b/libc/sysdeps/linux/common/fallocate64.c
index cf75693d6..1aa351ebe 100644
--- a/libc/sysdeps/linux/common/fallocate64.c
+++ b/libc/sysdeps/linux/common/fallocate64.c
@@ -13,6 +13,7 @@
#include <fcntl.h>
#include <bits/kernel-features.h>
#include <stdint.h>
+#include <errno.h>
#if defined __NR_fallocate
@@ -27,9 +28,11 @@ int attribute_hidden __libc_fallocate64(int fd, int mode, __off64_t offset,
INTERNAL_SYSCALL_DECL(err);
ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode,
OFF64_HI_LO (offset), OFF64_HI_LO (len)));
- if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
- return INTERNAL_SYSCALL_ERRNO (ret, err);
- return 0;
+ if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
+ __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
+ ret = -1;
+ }
+ return ret;
}
# if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU