ftruncate with LFS OFF (was Re: [PATCH v2 24/46] ftruncate: Use ftruncate64 if arch does not have the ftruncate syscall)
Vineet Gupta
Vineet.Gupta1 at synopsys.com
Sat Dec 8 08:49:11 UTC 2012
On Saturday 08 December 2012 12:22 PM, Vineet Gupta wrote:
> On Monday 26 November 2012 07:54 PM, Markos Chandras wrote:
>> From: Markos Chandras <markos.chandras at imgtec.com>
>>
>> Signed-off-by: Markos Chandras <markos.chandras at imgtec.com>
>> ---
>> libc/sysdeps/linux/common/ftruncate.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>>
>> diff --git a/libc/sysdeps/linux/common/ftruncate.c b/libc/sysdeps/linux/common/ftruncate.c
>> index 3bdef3f..72f86f9 100644
>> --- a/libc/sysdeps/linux/common/ftruncate.c
>> +++ b/libc/sysdeps/linux/common/ftruncate.c
>> @@ -11,5 +11,14 @@
>> #include <unistd.h>
>>
>>
>> +#if defined(__NR_ftruncate64) && !defined(__NR_ftruncate)
>> +int ftruncate(int fd, __off_t length)
>> +{
>> + return ftruncate64(fd, length);
>> +}
>> +libc_hidden_def(ftruncate);
>> +
>> +#else
>> _syscall2(int, ftruncate, int, fd, __off_t, length)
>> libc_hidden_def(ftruncate)
>> +#endif
>>
> In my local tests this fails with uClibc w/o LFS because ftruncate64()
> is only defined for LFS. Same goes for truncate64 and lseek64.
> So your libc (non LFS) will build fine but will have undefined refs
> which will show up when linking the app.
>
> arc-linux-uclibc-nm -u lib/libc.so.0
> ...
> U ftruncate64
> U lseek64
> U truncate64
>
> There are 2 approaches to fix this - either fix the __UCLIBC_HAS_LFS__
> gaurd in ftruncate64.c (and friends) or replicate the logic in
> fruncate.c - which gets messy given that we need to handle both WORDSIZE
> 32 and 64.
Following works for me !
int ftruncate(int fd, __off_t length)
{
#if defined __UCLIBC_HAS_LFS__
return ftruncate64(fd, length);
#elif __WORDSIZE == 32
uint32_t high = 0;
return INLINE_SYSCALL(ftruncate64, 3, fd,
__LONG_LONG_PAIR (high, length));
/* No need to handle __WORDSIZE == 64 as kernel won't define
__NR_ftruncate64 */
#endif
}
More information about the uClibc
mailing list