truncate64.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /* truncate64 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_truncate64
  16. # include <bits/wordsize.h>
  17. # if __WORDSIZE == 64
  18. _syscall2(int, truncate64, const char *, path, __off64_t, length)
  19. # elif __WORDSIZE == 32
  20. # include <endian.h>
  21. # include <stdint.h>
  22. int truncate64(const char * path, __off64_t length)
  23. {
  24. # if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
  25. return INLINE_SYSCALL(truncate64, 4, path, 0, OFF64_HI_LO(length));
  26. # else
  27. return INLINE_SYSCALL(truncate64, 3, path, OFF64_HI_LO(length));
  28. # endif
  29. }
  30. # else
  31. # error Your machine is not 64 bit nor 32 bit, I am dazed and confused.
  32. # endif
  33. #else
  34. # include <errno.h>
  35. int truncate64(const char * path, __off64_t length)
  36. {
  37. __off_t x = (__off_t) length;
  38. if (x == length) {
  39. return truncate(path, x);
  40. }
  41. __set_errno((x < 0) ? EINVAL : EFBIG);
  42. return -1;
  43. }
  44. #endif /* __NR_truncate64 */
  45. libc_hidden_def(truncate64)