curl-library
Re: curlopt_seekfunction
Date: Fri, 30 Sep 2016 16:21:35 -0400
Here is the correct code snippet. Copied from wrong place. Apologies for
the earlier incorrect code.
res = curl_easy_setopt(d_curl, CURLOPT_SEEKDATA, *userp);
if (res != CURLE_OK)
throw CurlError(res);
res = curl_easy_setopt(*userp, CURLOPT_SEEKFUNCTION, seek_callback);
if (res != CURLE_OK)
throw CurlError(res);
int seek_callback(void *userp, curl_off_t offset, int origin){
FILE* in = static_cast<FILE *>(userp);
long f_offset = (long) offset;
int ret = fseek(in, f_offset, origin);
return ret;
}
On Fri, Sep 30, 2016 at 4:05 PM, Biju N <bijuatapache_at_gmail.com> wrote:
> Hi Dan,
> Thanks for the response. The following is the seek function call back
>
> int seek_callback(void *userp, curl_off_t offset, int origin){
> FILE* in = static_cast<FILE *>userp;
> long f_offset = (long) offset;
> int ret = fseek(in, f_offset, origin);
> return ret;
> }
>
>
> The following is how curl opt is set
>
> void* userp;
>
> res = curl_easy_setopt(d_curl, CURLOPT_SEEKDATA, *userp);
> if (res != CURLE_OK)
> throw CurlError(res);
> res = curl_easy_setopt(*userp, CURLOPT_SEEKFUNCTION, seek_callback);
> if (res != CURLE_OK)
> throw CurlError(res);
>
> Please let me know if something is done incorrectly.
>
> Thanks,
> Biju
>
> On Thu, Sep 29, 2016 at 2:00 PM, Dan Fandrich <dan_at_coneharvesters.com>
> wrote:
>
>> On Wed, Sep 28, 2016 at 02:17:00PM -0400, Biju N wrote:
>> > Hello There,
>> > If you have defined and used curlopt_seekfunction, could you please
>> share a
>> > sample. Currently I am trying to pass the values from the call back to
>> "fseek"
>> > by casting the void* and offset without success.
>> >
>> > void* is cast to file* and offset to int. Not sure whether that is the
>> correct
>> > approach. Any help with this is much appreciated.
>>
>> Can you show us the code snippet doing this? As long as you set the FILE*
>> with
>> CURLOPT_SEEKDATA, and as long as your fseek() takes an int (it's probably
>> a
>> long) your approach sounds fine.
>>
>> >>> Dan
>> -------------------------------------------------------------------
>> List admin: https://cool.haxx.se/list/listinfo/curl-library
>> Etiquette: https://curl.haxx.se/mail/etiquette.html
>
>
>
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-09-30