curl-library
Re: Seek function
Date: Thu, 10 Jan 2008 10:40:08 +0100
Am Donnerstag, 10. Januar 2008 00:46 schrieb Daniel Stenberg:
> My main headache right now is to make the curl tool use it, and for that to
> work smoothly it can't use fseek() since that isn't doing 64bit seeks on
> Windows, so I need to switch to lseek() (and our lseek windows define
> trick) and for that to work I need to replace the existing fopen(), fread()
> calls and more... I think I'll save that work for a separate commit (and
> day) though.
You could define your own seek function that uses fseek multiple times like
this (not tested, but AFAIK should work with Windows):
#define MAX_SEEK_OFFSET 2147483647
void my_seek (FILE* hnd, curl_off_t offset, int origin)
{
curl_off_t passed = 0;
fseek(hnd, 0, SEEK_SET);
do {
long int new_offset =
(offset > MAX_SEEK_OFFSET ? MAX_SEEK_OFFSET : offset);
fseek(hnd, new_offset, SEEK_CUR);
passed += new_offset;
} while (passed != offset);
}
Received on 2008-01-10