Sortix volatile manual
This manual documents Sortix volatile, a development build that has not been officially released. You can instead view this document in the latest official manual.
CURLOPT_READFUNCTION(3) | Library Functions Manual | CURLOPT_READFUNCTION(3) |
NAME
CURLOPT_READFUNCTION - read callback for data uploadsSYNOPSIS
#include <curl/curl.h>
size_t read_callback(char *buffer, size_t size, size_t nitems, void *userdata);
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_READFUNCTION, read_callback);
DESCRIPTION
Pass a pointer to your callback function, as the prototype shows above.DEFAULT
fread(3)PROTOCOLS
This functionality affects all supported protocolsEXAMPLE
size_t read_callback(char *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;
}
int main(int argc, char **argv)
{
FILE *file = fopen(argv[1], "rb");
CURLcode result;
CURL *curl = curl_easy_init();
if(curl) {
/* set callback to use */
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
/* pass in suitable argument to callback */
curl_easy_setopt(curl, CURLOPT_READDATA, (void *)file);
result = curl_easy_perform(curl);
}
}
HISTORY
CURL_READFUNC_PAUSE return code was added in 7.18.0 and CURL_READFUNC_ABORT was added in 7.12.1.AVAILABILITY
Added in curl 7.1RETURN VALUE
This returns CURLE_OK.SEE ALSO
CURLOPT_POST(3), CURLOPT_READDATA(3), CURLOPT_SEEKFUNCTION(3), CURLOPT_UPLOAD(3), CURLOPT_UPLOAD_BUFFERSIZE(3), CURLOPT_WRITEFUNCTION(3)2024-11-23 | libcurl |