1CURLOPT_SEEKFUNCTION(3) curl_easy_setopt options CURLOPT_SEEKFUNCTION(3)
2
3
4
6 CURLOPT_SEEKFUNCTION - user callback for seeking in input stream
7
9 #include <curl/curl.h>
10
11 /* These are the return codes for the seek callbacks */
12 #define CURL_SEEKFUNC_OK 0
13 #define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */
14 #define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking cannot be done, so
15 libcurl might try other means instead */
16
17 int seek_callback(void *userp, curl_off_t offset, int origin);
18
19 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_callback);
20
22 Pass a pointer to your callback function, which should match the proto‐
23 type shown above.
24
25 This function gets called by libcurl to seek to a certain position in
26 the input stream and can be used to fast forward a file in a resumed
27 upload (instead of reading all uploaded bytes with the normal read
28 function/callback). It is also called to rewind a stream when data has
29 already been sent to the server and needs to be sent again. This may
30 happen when doing an HTTP PUT or POST with a multi-pass authentication
31 method, or when an existing HTTP connection is reused too late and the
32 server closes the connection. The function shall work like fseek(3) or
33 lseek(3) and it gets SEEK_SET, SEEK_CUR or SEEK_END as argument for
34 origin, although libcurl currently only passes SEEK_SET.
35
36 userp is the pointer you set with CURLOPT_SEEKDATA(3).
37
38 The callback function must return CURL_SEEKFUNC_OK on success,
39 CURL_SEEKFUNC_FAIL to cause the upload operation to fail or CURL_SEEK‐
40 FUNC_CANTSEEK to indicate that while the seek failed, libcurl is free
41 to work around the problem if possible. The latter can sometimes be
42 done by instead reading from the input or similar.
43
44 If you forward the input arguments directly to fseek(3) or lseek(3),
45 note that the data type for offset is not the same as defined for
46 curl_off_t on many systems!
47
49 By default, this is NULL and unused.
50
52 HTTP, FTP, SFTP
53
55 static int seek_cb(void *userp, curl_off_t offset, int origin)
56 {
57 struct data *d = (struct data *)userp;
58 lseek(our_fd, offset, origin);
59 return CURL_SEEKFUNC_OK;
60 }
61
62 {
63 struct data seek_data;
64 curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_cb);
65 curl_easy_setopt(CURL *handle, CURLOPT_SEEKDATA, &seek_data);
66 }
67
69 Added in 7.18.0
70
72 Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION
73 if not.
74
76 CURLOPT_SEEKDATA(3), CURLOPT_IOCTLFUNCTION(3),
77
78
79
80libcurl 7.82.0 October 31, 2021 CURLOPT_SEEKFUNCTION(3)