cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: fseek() and large files

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Mon, 7 Mar 2005 10:30:49 -0800

> Dan, you modified the fseek() in src/main.c:3779 the other day from
>
> fseek(outs.stream, 0, SEEK_END);
>
> to
>
> fseek(outs.stream, outs.init, SEEK_SET);
>
> Was there a specific reason for this?

Yes, twofold: to do the right thing even when ftruncate() fails, and to
support systems that don't have ftruncate(). The former is probably a
marginal case (it seems unlikely that a ftruncate will fail but an fseek
succeeds), but the latter is a definite problem since I'm working on a
port to such a system.

> Since 'outs.init' is potentially a 64 bit file size and fseek() takes a
> 'long', this will break when reaching beyond 2GB...
>
> See for example this warning:
>
> http://curl.haxx.se/auto/log.cgi?id=20050307072208-32314#prob1

Ahah. I was under the impression that fseek took an fpos_t as the position
parameter and would therefore be safe with a large file enabled libc,
but you're right--it just takes a long. fsetpos() is the function I wanted
there, except that it still won't do the right thing if libcurl and the
kernel support large files but libc doesn't.

I'll change it back to the old way if ftruncate is available and use the
fsetpos method as a fallback if not.

>>> Dan
Received on 2005-03-07