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