fallocate64.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * fallocate64() for MIPS uClibc
  3. *
  4. * Copyright (C) 2026 Ramin Moussavi <ramin.moussavi@yacoub.de>
  5. *
  6. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <_lfs_64.h>
  9. #include <sys/syscall.h>
  10. #include <bits/wordsize.h>
  11. #if defined __NR_fallocate && __WORDSIZE == 32
  12. # include <fcntl.h>
  13. # include <endian.h>
  14. # include <errno.h>
  15. # include <sgidefs.h>
  16. extern __typeof(fallocate64) __libc_fallocate64 attribute_hidden;
  17. int attribute_hidden __libc_fallocate64(int fd, int mode, __off64_t offset,
  18. __off64_t len)
  19. {
  20. int ret;
  21. INTERNAL_SYSCALL_DECL(err);
  22. # if _MIPS_SIM == _ABIO32
  23. /* o32 splits each 64-bit argument into a register pair. */
  24. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode,
  25. OFF64_HI_LO (offset), OFF64_HI_LO (len)));
  26. # else /* N32: 64-bit registers, pass each 64-bit argument whole. */
  27. ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len));
  28. # endif
  29. if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) {
  30. __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err));
  31. ret = -1;
  32. }
  33. return ret;
  34. }
  35. # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
  36. strong_alias(__libc_fallocate64,fallocate64)
  37. # endif
  38. #endif