posix_fallocate.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * posix_fallocate() for uClibc
  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. int posix_fallocate(int fd, __off_t offset, __off_t len)
  16. {
  17. int ret;
  18. # if __WORDSIZE == 32
  19. uint32_t off_low = offset;
  20. uint32_t len_low = len;
  21. /* may assert that these >>31 are 0 */
  22. uint32_t zero = 0;
  23. INTERNAL_SYSCALL_DECL(err);
  24. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0,
  25. __LONG_LONG_PAIR (zero, off_low),
  26. __LONG_LONG_PAIR (zero, len_low)));
  27. # elif __WORDSIZE == 64
  28. INTERNAL_SYSCALL_DECL(err);
  29. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, 0, offset, len));
  30. # else
  31. # error your machine is neither 32 bit or 64 bit ... it must be magical
  32. #endif
  33. if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
  34. return INTERNAL_SYSCALL_ERRNO (ret, err);
  35. return 0;
  36. }
  37. # if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
  38. strong_alias(posix_fallocate,posix_fallocate64)
  39. # endif
  40. #endif