summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/posix_fallocate.c
diff options
context:
space:
mode:
authorYuriy Kolerov <yuriy.kolerov@synopsys.com>2015-09-23 15:43:39 +0300
committerWaldemar Brodkorb <wbx@openadk.org>2015-10-05 22:07:08 +0200
commit9fae2ad9937279c9f7f40975ac14cb7b57f4a36d (patch)
tree670781363cabeb335c490ee1f47e305b9bbf3a33 /libc/sysdeps/linux/common/posix_fallocate.c
parent4480f9b5558906fce2c35f1819d4e1fe5922a9fa (diff)
libc: posix_fallocate must return an error number on failure
posix_fallocate implementation in uClibc relies on fallocate system call - it just returns what fallocate returns. However fallocate returns -1 on failure and assigns an error number to errno variable. In the same time posix_fallocate must return an error number but not -1. What does this patch: if fallocate returns -1 then posix_fallocate returns errno. Otherwise posix_fallocate returns 0 on success. However there is a side effect - posix_fallocate sets errno on failure because fallocate does it. But POSIX does not forbid it thus it's not a problem. Signed-off-by: Yuriy Kolerov <yuriy.kolerov@synopsys.com>
Diffstat (limited to 'libc/sysdeps/linux/common/posix_fallocate.c')
-rw-r--r--libc/sysdeps/linux/common/posix_fallocate.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/libc/sysdeps/linux/common/posix_fallocate.c b/libc/sysdeps/linux/common/posix_fallocate.c
index 76771e353..2316cfdcd 100644
--- a/libc/sysdeps/linux/common/posix_fallocate.c
+++ b/libc/sysdeps/linux/common/posix_fallocate.c
@@ -12,12 +12,15 @@
#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;
int posix_fallocate(int fd, __off_t offset, __off_t len)
{
- return __libc_fallocate(fd, 0, offset, len);
+ if (__libc_fallocate(fd, 0, offset, len))
+ return errno;
+ return 0;
}
# if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
strong_alias(posix_fallocate,posix_fallocate64)