posix_fallocate64.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. # if __WORDSIZE == 64
  16. /* Can use normal posix_fallocate() */
  17. # elif __WORDSIZE == 32
  18. int posix_fallocate64(int fd, __off64_t offset, __off64_t len)
  19. {
  20. int ret;
  21. uint32_t off_low = offset & 0xffffffff;
  22. uint32_t off_high = offset >> 32;
  23. uint32_t len_low = len & 0xffffffff;
  24. uint32_t len_high = len >> 32;
  25. INTERNAL_SYSCALL_DECL(err);
  26. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0,
  27. __LONG_LONG_PAIR (off_high, off_low),
  28. __LONG_LONG_PAIR (len_high, len_low)));
  29. if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
  30. return INTERNAL_SYSCALL_ERRNO (ret, err);
  31. return 0;
  32. }
  33. # else
  34. # error your machine is neither 32 bit or 64 bit ... it must be magical
  35. # endif
  36. #endif