mirror of
https://github.com/curl/curl.git
synced 2026-08-25 17:33:32 +03:00
examples: improve global init, error checks and returning errors
- add `curl_global_init()` and `curl_global_cleanup()` where missing. - check the result of `curl_global_init()` where missing. - return the last curl error from `main()`. - drop Win32-specific socket initialization in favor of `curl_global_init()`. - rename some outliers to `res` for curl result code. - fix cleanup in some error cases. Inspired by Joshua's report on examples. Closes #19053
This commit is contained in:
parent
3049c8e0a0
commit
4c7507daf9
129 changed files with 990 additions and 485 deletions
|
|
@ -207,6 +207,7 @@ static size_t mywrite(char *ptr, size_t size, size_t nmemb, void *userdata)
|
|||
|
||||
int main(void)
|
||||
{
|
||||
CURLcode res;
|
||||
unsigned i;
|
||||
int total_failed = 0;
|
||||
char errbuf[CURL_ERROR_SIZE] = { 0, };
|
||||
|
|
@ -222,9 +223,10 @@ int main(void)
|
|||
transfer[1].bodyfile = "400.txt";
|
||||
transfer[1].logfile = "400_transfer_log.txt";
|
||||
|
||||
if(curl_global_init(CURL_GLOBAL_DEFAULT)) {
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res) {
|
||||
fprintf(stderr, "curl_global_init failed\n");
|
||||
return 1;
|
||||
return (int)res;
|
||||
}
|
||||
|
||||
/* You could enable global tracing for extra verbosity when verbosity is
|
||||
|
|
@ -334,5 +336,7 @@ int main(void)
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
return total_failed ? 1 : 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue