GNURLOPT_SEEKFUNCTION(3)
π NAME π
okay so this is GNURLOPT_SEEKFUNCTION(3), straight outta the curl_easy_setopt options manual, and the whole main-character energy is CURLOPT_SEEKFUNCTION β user callback for seeking in input stream. No cap, that's the vibe. π
β¨ SYNOPSIS β¨
bestie, here's the exact shape of it:
#include <gnurl/curl.h>
/* These are the return codes for the seek callbacks */
#define CURL_SEEKFUNC_OK 0
#define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */
#define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking can't be done, so
libcurl might try other means instead */
int seek_callback(void *userp, curl_off_t offset, int origin);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_callback);
π¦ DESCRIPTION π¦
You pass a pointer to your callback function, and it should match the prototype shown above. That's the whole entrance exam, bestie. π«Ά
This function gets called by libcurl to seek to a certain position in the input stream, and it can be used to fast forward a file in a resumed upload β instead of reading all uploaded bytes with the normal read function/callback. It is also called to rewind a stream when data has already been sent to the server and needs to be sent again. This may happen when doing an HTTP PUT or POST with a multi-pass authentication method, or when an existing HTTP connection is reused too late and the server closes the connection. The function shall work like fseek(3) or lseek(3), and it gets SEEK_SET, SEEK_CUR or SEEK_END as argument for origin, although libcurl currently only passes SEEK_SET. periodt. π
userp is the pointer you set with CURLOPT_SEEKDATA(3).
The callback function must return CURL_SEEKFUNC_OK on success, CURL_SEEKFUNC_FAIL to cause the upload operation to fail, or CURL_SEEKFUNC_CANTSEEK to indicate that while the seek failed, libcurl is free to work around the problem if possible. The latter can sometimes be done by instead reading from the input or similar. slay, but make it accurate. β¨
If you forward the input arguments directly tofseek(3)orlseek(3), note that the data type for offset is not the same as defined forcurl_off_ton many systems! β οΈ
π DEFAULT π
By default, this is NULL and unused. Cute, quiet, not doing anything. π
π PROTOCOLS π
HTTP, FTP, SFTP. That's the set. πΈ
π₯ EXAMPLE π₯
static int seek_cb(void *userp, curl_off_t offset, int origin)
{
struct data *d = (struct data *)userp;
lseek(our_fd, offset, origin);
return CURL_SEEKFUNC_OK;
}
{
struct data seek_data;
curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_cb);
curl_easy_setopt(CURL *handle, CURLOPT_SEEKDATA, &seek_data);
}
β AVAILABILITY β
Added in 7.18.0. iconic behavior, honestly. π
π RETURN VALUE π
Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
π«Ά SEE ALSO π«Ά
yes, the trailing comma is in the original, bestie. iykyk. π
mwah π this page is from libcurl 7.37.0, dated 16 Jun 2014, and it lives under the GNURLOPT_SEEKFUNCTION(3) manual name β bye bestie, go seek responsibly π§ββοΈ
π¦ where this page comes from
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms