ftruncate64.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  3. *
  4. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  5. *
  6. * ftruncate64 syscall. Copes with 64 bit and 32 bit machines
  7. * and on 32 bit machines this sends things into the kernel as
  8. * two 32-bit arguments (high and low 32 bits of length) that
  9. * are ordered based on endianess. It turns out endian.h has
  10. * just the macro we need to order things, OFF64_HI_LO.
  11. */
  12. #include <_lfs_64.h>
  13. #include <sys/syscall.h>
  14. #include <unistd.h>
  15. #ifdef __NR_ftruncate64
  16. # include <bits/wordsize.h>
  17. # if __WORDSIZE == 64
  18. /* For a 64 bit machine, life is simple... */
  19. _syscall2(int, ftruncate64, int, fd, __off64_t, length)
  20. # elif __WORDSIZE == 32
  21. # include <endian.h>
  22. # include <stdint.h>
  23. /* The exported ftruncate64 function. */
  24. int ftruncate64 (int fd, __off64_t length)
  25. {
  26. # if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  27. return INLINE_SYSCALL(ftruncate64, 4, fd, 0, OFF64_HI_LO(length));
  28. # else
  29. return INLINE_SYSCALL(ftruncate64, 3, fd, OFF64_HI_LO(length));
  30. # endif
  31. }
  32. # else /* __WORDSIZE */
  33. # error Your machine is not 64 bit or 32 bit, I am dazed and confused.
  34. # endif /* __WORDSIZE */
  35. #else /* __NR_ftruncate64 */
  36. # include <errno.h>
  37. int ftruncate64 (int fd, __off64_t length)
  38. {
  39. __off_t x = (__off_t) length;
  40. if (x == length) {
  41. return ftruncate(fd, x);
  42. }
  43. __set_errno((x < 0) ? EINVAL : EFBIG);
  44. return -1;
  45. }
  46. #endif /* __NR_ftruncate64 */
  47. libc_hidden_def(ftruncate64)