fallocate.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #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. int ret;
  19. # if __WORDSIZE == 32
  20. uint32_t off_low = offset;
  21. uint32_t len_low = len;
  22. /* may assert that these >>31 are 0 */
  23. uint32_t zero = 0;
  24. INTERNAL_SYSCALL_DECL(err);
  25. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode,
  26. __LONG_LONG_PAIR (zero, off_low),
  27. __LONG_LONG_PAIR (zero, len_low)));
  28. # elif __WORDSIZE == 64
  29. INTERNAL_SYSCALL_DECL(err);
  30. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len));
  31. # else
  32. # error your machine is neither 32 bit or 64 bit ... it must be magical
  33. # endif
  34. if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
  35. return INTERNAL_SYSCALL_ERRNO (ret, err);
  36. return 0;
  37. }
  38. # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
  39. strong_alias(__libc_fallocate,fallocate)
  40. # if __WORDSIZE == 64
  41. strong_alias(__libc_fallocate,fallocate64)
  42. # endif
  43. # endif
  44. #endif