#### # # # # _stat# # _fstat# _fileno# # < 0x070c03## ( *userp, curl_off_t offset, origin){ FILE *fp = (FILE *) userp; (-1 == fseek(fp, () offset, origin)) CURL_SEEKFUNC_CANTSEEK; CURL_SEEKFUNC_OK;} size_t( *ptr, size_t size, size_t nmemb, *stream){ size_t nread; nread = fread(ptr, size, nmemb, stream); (nread > 0) { fprintf(stderr,, ()nread); } nread;} ( argc, **argv){ CURL *curl; CURLcode res; FILE *fp; stat file_info; *file; *url; (argc < 3) 1; file = argv[1]; url = argv[2]; fp = fopen(file,);(!fp) 2; # stat(file, &file_info);# fstat(fileno(fp), &file_info);# curl_global_init(CURL_GLOBAL_ALL); curl =curl_easy_init();(curl) {curl_easy_setopt(curl,CURLOPT_READFUNCTION, read_callback); curl_easy_setopt(curl,CURLOPT_READDATA, ( *) fp); curl_easy_setopt(curl,CURLOPT_SEEKFUNCTION, my_seek); curl_easy_setopt(curl,CURLOPT_SEEKDATA, ( *) fp); curl_easy_setopt(curl,CURLOPT_UPLOAD, 1L); curl_easy_setopt(curl,CURLOPT_URL, url); curl_easy_setopt(curl,CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size); curl_easy_setopt(curl,CURLOPT_HTTPAUTH, ()CURLAUTH_ANY); curl_easy_setopt(curl,CURLOPT_USERPWD,); res =curl_easy_perform(curl);(res != CURLE_OK) fprintf(stderr,,curl_easy_strerror(res)); curl_easy_cleanup(curl); } fclose(fp); curl_global_cleanup(); 0;}
A real-world application will of course properly check every return value andexit correctly at the first serious error.