mirror of
https://github.com/curl/curl.git
synced 2026-08-05 11:46:14 +03:00
examples: check more errors, fix cleanups, scope variables
Inspired by Joshua's report on examples. Closes #19055
This commit is contained in:
parent
61dcb56743
commit
64ed2ea196
42 changed files with 874 additions and 785 deletions
|
|
@ -38,10 +38,10 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
static const char *pagefilename = "page.out";
|
||||
|
||||
CURLcode res;
|
||||
CURL *curl_handle;
|
||||
static const char *pagefilename = "page.out";
|
||||
FILE *pagefile;
|
||||
|
||||
if(argc < 2) {
|
||||
printf("Usage: %s <URL>\n", argv[0]);
|
||||
|
|
@ -56,36 +56,39 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* init the curl session */
|
||||
curl_handle = curl_easy_init();
|
||||
if(curl_handle) {
|
||||
FILE *pagefile;
|
||||
|
||||
/* set URL to get here */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, argv[1]);
|
||||
/* set URL to get here */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_URL, argv[1]);
|
||||
|
||||
/* Switch on full protocol/debug output while testing */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
|
||||
/* Switch on full protocol/debug output while testing */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
|
||||
|
||||
/* disable progress meter, set to 0L to enable it */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
|
||||
/* disable progress meter, set to 0L to enable it */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
|
||||
|
||||
/* send all data to this function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
|
||||
/* send all data to this function */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
|
||||
|
||||
/* open the file */
|
||||
pagefile = fopen(pagefilename, "wb");
|
||||
if(pagefile) {
|
||||
/* open the file */
|
||||
pagefile = fopen(pagefilename, "wb");
|
||||
if(pagefile) {
|
||||
|
||||
/* write the page body to this file handle */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
|
||||
/* write the page body to this file handle */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
|
||||
|
||||
/* get it! */
|
||||
res = curl_easy_perform(curl_handle);
|
||||
/* get it! */
|
||||
res = curl_easy_perform(curl_handle);
|
||||
|
||||
/* close the header file */
|
||||
fclose(pagefile);
|
||||
/* close the header file */
|
||||
fclose(pagefile);
|
||||
}
|
||||
|
||||
/* cleanup curl stuff */
|
||||
curl_easy_cleanup(curl_handle);
|
||||
}
|
||||
|
||||
/* cleanup curl stuff */
|
||||
curl_easy_cleanup(curl_handle);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return (int)res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue