fallocate.c 1.2 KB

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