Skip to content
Browse files

CURLOPT_READFUNCTION.3: provide inline example

... instead of mentioning one in another place
  • Loading branch information...
bagder committed Aug 12, 2019
1 parent fb6d46a commit f88d865bf4612ee9ce6b311952ae6d2f2bbf05c0
Showing with 31 additions and 2 deletions.
  1. +31 −2 docs/libcurl/opts/CURLOPT_READFUNCTION.3
@@ -69,8 +69,37 @@ The default internal read callback is fread().
This is used for all protocols when doing uploads.
Here's an example setting a read callback for reading that to upload to an FTP
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);
CURL_READFUNC_PAUSE return code was added in 7.18.0 and CURL_READFUNC_ABORT
was added in 7.12.1.

0 comments on commit f88d865

Please sign in to comment.
You can’t perform that action at this time.