CURLOPT_SEEKFUNCTION.3 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. .\" generated by cd2nroff 0.1 from CURLOPT_SEEKFUNCTION.md
  2. .TH CURLOPT_SEEKFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_SEEKFUNCTION \- user callback for seeking in input stream
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. /* These are the return codes for the seek callbacks */
  9. #define CURL_SEEKFUNC_OK 0
  10. #define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */
  11. #define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking cannot be done, so
  12. libcurl might try other means instead */
  13. int seek_callback(void *clientp, curl_off_t offset, int origin);
  14. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_callback);
  15. .fi
  16. .SH DESCRIPTION
  17. Pass a pointer to your callback function, which should match the prototype
  18. shown above.
  19. This function gets called by libcurl to seek to a certain position in the
  20. input stream and can be used to fast forward a file in a resumed upload
  21. (instead of reading all uploaded bytes with the normal read
  22. function/callback). It is also called to rewind a stream when data has already
  23. been sent to the server and needs to be sent again. This may happen when doing
  24. an HTTP PUT or POST with a multi\-pass authentication method, or when an
  25. existing HTTP connection is reused too late and the server closes the
  26. connection. The function shall work like fseek(3) or lseek(3) and it gets
  27. SEEK_SET, SEEK_CUR or SEEK_END as argument for \fIorigin\fP, although libcurl
  28. currently only passes SEEK_SET.
  29. \fIclientp\fP is the pointer you set with \fICURLOPT_SEEKDATA(3)\fP.
  30. The callback function must return \fICURL_SEEKFUNC_OK\fP on success,
  31. \fICURL_SEEKFUNC_FAIL\fP to cause the upload operation to fail or
  32. \fICURL_SEEKFUNC_CANTSEEK\fP to indicate that while the seek failed, libcurl
  33. is free to work around the problem if possible. The latter can sometimes be
  34. done by instead reading from the input or similar.
  35. If you forward the input arguments directly to fseek(3) or lseek(3), note that
  36. the data type for \fIoffset\fP is not the same as defined for curl_off_t on
  37. many systems!
  38. .SH DEFAULT
  39. NULL
  40. .SH PROTOCOLS
  41. This functionality affects all supported protocols
  42. .SH EXAMPLE
  43. .nf
  44. #include <unistd.h> /* for lseek */
  45. struct data {
  46. int our_fd;
  47. };
  48. static int seek_cb(void *clientp, curl_off_t offset, int origin)
  49. {
  50. struct data *d = (struct data *)clientp;
  51. lseek(d->our_fd, offset, origin);
  52. return CURL_SEEKFUNC_OK;
  53. }
  54. int main(void)
  55. {
  56. struct data seek_data;
  57. CURL *curl = curl_easy_init();
  58. if(curl) {
  59. curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, seek_cb);
  60. curl_easy_setopt(curl, CURLOPT_SEEKDATA, &seek_data);
  61. }
  62. }
  63. .fi
  64. .SH AVAILABILITY
  65. Added in curl 7.18.0
  66. .SH RETURN VALUE
  67. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  68. .SH SEE ALSO
  69. .BR CURLOPT_DEBUGFUNCTION (3),
  70. .BR CURLOPT_IOCTLFUNCTION (3),
  71. .BR CURLOPT_SEEKDATA (3),
  72. .BR CURLOPT_STDERR (3)