aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2019-08-12 09:20:04 +0200
committerDaniel Stenberg <daniel@haxx.se>2019-08-12 09:20:52 +0200
commitf88d865bf4612ee9ce6b311952ae6d2f2bbf05c0 (patch)
tree94e5df9502482386eab9c259455bcf12f354db9c /docs
parentfb6d46a7094ebe7c1379e0d7d44ab04354615102 (diff)
CURLOPT_READFUNCTION.3: provide inline example
... instead of mentioning one in another place
Diffstat (limited to 'docs')
-rw-r--r--docs/libcurl/opts/CURLOPT_READFUNCTION.333
1 files changed, 31 insertions, 2 deletions
diff --git a/docs/libcurl/opts/CURLOPT_READFUNCTION.3 b/docs/libcurl/opts/CURLOPT_READFUNCTION.3
index df6681c38..30b0925eb 100644
--- a/docs/libcurl/opts/CURLOPT_READFUNCTION.3
+++ b/docs/libcurl/opts/CURLOPT_READFUNCTION.3
@@ -69,8 +69,37 @@ The default internal read callback is fread().
.SH PROTOCOLS
This is used for all protocols when doing uploads.
.SH EXAMPLE
-Here's an example setting a read callback for reading that to upload to an FTP
-site: https://curl.haxx.se/libcurl/c/ftpupload.html
+.nf
+size_t read_callback(void *ptr, size_t size, size_t nmemb, void *userdata)
+{
+ FILE *readhere = (FILE *)userdata;
+ curl_off_t nread;
+
+ /* copy as much data as possible into the 'ptr' buffer, but no more than
+ 'size' * 'nmemb' bytes! */
+ size_t retcode = fread(ptr, size, nmemb, readhere);
+
+ nread = (curl_off_t)retcode;
+
+ fprintf(stderr, "*** We read %" CURL_FORMAT_CURL_OFF_T
+ " bytes from file\\n", nread);
+ return retcode;
+}
+
+void setup(char *uploadthis)
+{
+ FILE *file = fopen("rb", uploadthis);
+ CURLcode result;
+
+ /* set callback to use */
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
+
+ /* pass in suitable argument to callback */
+ curl_easy_setopt(curl, CURLOPT_READDATA, uploadthis);
+
+ result = curl_easy_perform(curl);
+}
+.fi
.SH AVAILABILITY
CURL_READFUNC_PAUSE return code was added in 7.18.0 and CURL_READFUNC_ABORT
was added in 7.12.1.