fallocate.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include <sys/syscall.h>
  10. #include <fcntl.h>
  11. #include <bits/kernel-features.h>
  12. #include <stdint.h>
  13. #include <errno.h>
  14. #if defined __NR_fallocate
  15. extern __typeof(fallocate) __libc_fallocate attribute_hidden;
  16. int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t len)
  17. {
  18. # if __WORDSIZE == 32
  19. return fallocate64(fd, mode, offset, len);
  20. # elif __WORDSIZE == 64
  21. int ret;
  22. INTERNAL_SYSCALL_DECL(err);
  23. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len));
  24. if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
  25. __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
  26. ret = -1;
  27. }
  28. return ret;
  29. # else
  30. # error your machine is neither 32 bit or 64 bit ... it must be magical
  31. # endif
  32. }
  33. # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
  34. strong_alias(__libc_fallocate,fallocate)
  35. # if __WORDSIZE == 64
  36. strong_alias(__libc_fallocate,fallocate64)
  37. # endif
  38. # endif
  39. #endif