mirror of
https://github.com/curl/curl.git
synced 2026-08-24 16:23:34 +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
|
|
@ -47,15 +47,22 @@ int main(void)
|
|||
FILE *ftpfile;
|
||||
FILE *respfile;
|
||||
|
||||
res = curl_global_init(CURL_GLOBAL_ALL);
|
||||
if(res)
|
||||
return (int)res;
|
||||
|
||||
/* local filename to store the file as */
|
||||
ftpfile = fopen(FTPBODY, "wb"); /* b is binary, needed on Windows */
|
||||
if(!ftpfile)
|
||||
if(!ftpfile) {
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* local filename to store the FTP server's response lines in */
|
||||
respfile = fopen(FTPHEADERS, "wb"); /* b is binary, needed on Windows */
|
||||
if(!respfile) {
|
||||
fclose(ftpfile);
|
||||
curl_global_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -81,5 +88,5 @@ int main(void)
|
|||
fclose(ftpfile); /* close the local file */
|
||||
fclose(respfile); /* close the response file */
|
||||
|
||||
return 0;
|
||||
return (int)res;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue