Re: Bug report: curl win32 ftruncate64 not working correctly.
Date: Fri, 14 Dec 2007 14:39:09 +0100
My 2 cents...
All line number references are relative to
POSIX ftruncate() truncates the file but does not move the file
pointer. This is the reason for line 4634 trying to reposition the
file pointer to the new truncated position.
Our ftruncate64() tries to emulate POSIX ftruncate() keeping the file
pointer at its original position. BUT this is the actual problem. See
line 339. It shouldn't move the file pointer to its original position,
just keep it at the truncated position. Otherwise no truncation will
Since we only use ftruncate() to truncate the file and not extend it
beyond its actual end.
The following ftruncate64() should do the trick:
static int ftruncate64 (int fd, curl_off_t where)
if(_lseeki64(fd, 0, SEEK_CUR) < 0)
if (_lseeki64(fd, where, SEEK_SET) < 0)
if(_write(fd, 0, 0) < 0)
But it shoul be taken into consideration that the lines 4634 and 4640
should not be executed when our ftruncate64() is used.
So most probably a private function called ftruncate_and_set_fp() or
something similar should be used to wrap POSIX and WIN32
-- -=[Yang]=-Received on 2007-12-14