1 /*
2  * fallocate() for uClibc - Based off of posix_fallocate() by Erik Andersen
3  * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
6  *
7  * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
8  */
9 
10 #include <sys/syscall.h>
11 #include <fcntl.h>
12 #include <bits/kernel-features.h>
13 #include <stdint.h>
14 #include <errno.h>
15 
16 #if defined __NR_fallocate
17 extern __typeof(fallocate) __libc_fallocate attribute_hidden;
__libc_fallocate(int fd,int mode,__off_t offset,__off_t len)18 int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t len)
19 {
20 # if __WORDSIZE == 32
21 	return fallocate64(fd, mode, offset, len);
22 # elif __WORDSIZE == 64
23 	int ret;
24 	INTERNAL_SYSCALL_DECL(err);
25 	ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len));
26 	if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
27 		__set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
28 		ret = -1;
29 	}
30 	return ret;
31 # else
32 # error your machine is neither 32 bit or 64 bit ... it must be magical
33 # endif
34 }
35 
36 # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
37 strong_alias(__libc_fallocate,fallocate)
38 #  if __WORDSIZE == 64
39 strong_alias(__libc_fallocate,fallocate64)
40 #  endif
41 # endif
42 #endif
43