CURLOPT_SEEKFUNCTION.3 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH CURLOPT_SEEKFUNCTION 3 "February 07, 2023" "libcurl 7.88.1" "curl_easy_setopt options"
  26. .SH NAME
  27. CURLOPT_SEEKFUNCTION \- user callback for seeking in input stream
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. /* These are the return codes for the seek callbacks */
  32. #define CURL_SEEKFUNC_OK 0
  33. #define CURL_SEEKFUNC_FAIL 1 /* fail the entire transfer */
  34. #define CURL_SEEKFUNC_CANTSEEK 2 /* tell libcurl seeking cannot be done, so
  35. libcurl might try other means instead */
  36. int seek_callback(void *clientp, curl_off_t offset, int origin);
  37. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_callback);
  38. .SH DESCRIPTION
  39. Pass a pointer to your callback function, which should match the prototype
  40. shown above.
  41. This function gets called by libcurl to seek to a certain position in the
  42. input stream and can be used to fast forward a file in a resumed upload
  43. (instead of reading all uploaded bytes with the normal read
  44. function/callback). It is also called to rewind a stream when data has already
  45. been sent to the server and needs to be sent again. This may happen when doing
  46. an HTTP PUT or POST with a multi-pass authentication method, or when an
  47. existing HTTP connection is reused too late and the server closes the
  48. connection. The function shall work like fseek(3) or lseek(3) and it gets
  49. SEEK_SET, SEEK_CUR or SEEK_END as argument for \fIorigin\fP, although libcurl
  50. currently only passes SEEK_SET.
  51. \fIclientp\fP is the pointer you set with \fICURLOPT_SEEKDATA(3)\fP.
  52. The callback function must return \fICURL_SEEKFUNC_OK\fP on success,
  53. \fICURL_SEEKFUNC_FAIL\fP to cause the upload operation to fail or
  54. \fICURL_SEEKFUNC_CANTSEEK\fP to indicate that while the seek failed, libcurl
  55. is free to work around the problem if possible. The latter can sometimes be
  56. done by instead reading from the input or similar.
  57. If you forward the input arguments directly to fseek(3) or lseek(3), note that
  58. the data type for \fIoffset\fP is not the same as defined for curl_off_t on
  59. many systems!
  60. .SH DEFAULT
  61. By default, this is NULL and unused.
  62. .SH PROTOCOLS
  63. HTTP, FTP, SFTP
  64. .SH EXAMPLE
  65. .nf
  66. static int seek_cb(void *clientp, curl_off_t offset, int origin)
  67. {
  68. struct data *d = (struct data *)clientp;
  69. lseek(our_fd, offset, origin);
  70. return CURL_SEEKFUNC_OK;
  71. }
  72. {
  73. struct data seek_data;
  74. curl_easy_setopt(CURL *handle, CURLOPT_SEEKFUNCTION, seek_cb);
  75. curl_easy_setopt(CURL *handle, CURLOPT_SEEKDATA, &seek_data);
  76. }
  77. .fi
  78. .SH AVAILABILITY
  79. Added in 7.18.0
  80. .SH RETURN VALUE
  81. Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
  82. .SH "SEE ALSO"
  83. .BR CURLOPT_SEEKDATA "(3), " CURLOPT_IOCTLFUNCTION "(3), "