aboutsummaryrefslogtreecommitdiff
path: root/tests/libtest/lib505.c
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2006-10-25 05:59:46 +0000
committerYang Tse <yangsita@gmail.com>2006-10-25 05:59:46 +0000
commit384c8f356087178e4779d99d3e0e7f25331293aa (patch)
tree7b7d5aec819f6f47ccc3b28d7390ae62c036535b /tests/libtest/lib505.c
parentf44ef427a2fbe506a35548ebab2b503438d6a027 (diff)
Use curl_global_init() and curl_global_cleanup().
Improve cleanup in case of initialization failure.
Diffstat (limited to 'tests/libtest/lib505.c')
-rw-r--r--tests/libtest/lib505.c85
1 files changed, 52 insertions, 33 deletions
diff --git a/tests/libtest/lib505.c b/tests/libtest/lib505.c
index 7de0bc1e9..85ce38b32 100644
--- a/tests/libtest/lib505.c
+++ b/tests/libtest/lib505.c
@@ -42,6 +42,7 @@ int test(char *URL)
FILE *hd_src ;
int hd ;
struct_stat file_info;
+ struct curl_slist *hl;
struct curl_slist *headerlist=NULL;
const char *buf_1 = "RNFR 505";
@@ -73,51 +74,69 @@ int test(char *URL)
return -2; /* if this happens things are major weird */
}
- /* In windows, this will init the winsock stuff */
- curl_global_init(CURL_GLOBAL_ALL);
+ if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+ fprintf(stderr, "curl_global_init() failed\n");
+ fclose(hd_src);
+ return TEST_ERR_MAJOR_BAD;
+ }
/* get a curl handle */
- curl = curl_easy_init();
- if(curl) {
- struct curl_slist *hl;
- /* build a list of commands to pass to libcurl */
- hl = curl_slist_append(headerlist, buf_1);
- if(hl) {
- headerlist = curl_slist_append(hl, buf_2);
- if(hl)
- headerlist = hl;
- }
+ if ((curl = curl_easy_init()) == NULL) {
+ fprintf(stderr, "curl_easy_init() failed\n");
+ curl_global_cleanup();
+ fclose(hd_src);
+ return TEST_ERR_MAJOR_BAD;
+ }
- /* enable uploading */
- curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
+ /* build a list of commands to pass to libcurl */
- /* enable verbose */
- curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE) ;
+ if ((hl = curl_slist_append(headerlist, buf_1)) == NULL) {
+ fprintf(stderr, "curl_slist_append() failed\n");
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ fclose(hd_src);
+ return TEST_ERR_MAJOR_BAD;
+ }
+ if ((headerlist = curl_slist_append(hl, buf_2)) == NULL) {
+ fprintf(stderr, "curl_slist_append() failed\n");
+ curl_slist_free_all(hl);
+ curl_easy_cleanup(curl);
+ curl_global_cleanup();
+ fclose(hd_src);
+ return TEST_ERR_MAJOR_BAD;
+ }
+ headerlist = hl;
- /* specify target */
- curl_easy_setopt(curl,CURLOPT_URL, URL);
+ /* enable uploading */
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
- /* pass in that last of FTP commands to run after the transfer */
- curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
+ /* enable verbose */
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE) ;
- /* now specify which file to upload */
- curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
+ /* specify target */
+ curl_easy_setopt(curl,CURLOPT_URL, URL);
- /* and give the size of the upload (optional) */
- curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
- (curl_off_t)file_info.st_size);
+ /* pass in that last of FTP commands to run after the transfer */
+ curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
- /* Now run off and do what you've been told! */
- res = curl_easy_perform(curl);
+ /* now specify which file to upload */
+ curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
- /* clean up the FTP commands list */
- curl_slist_free_all (headerlist);
+ /* and give the size of the upload (optional) */
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE,
+ (curl_off_t)file_info.st_size);
- /* always cleanup */
- curl_easy_cleanup(curl);
- }
- fclose(hd_src); /* close the local file */
+ /* Now run off and do what you've been told! */
+ res = curl_easy_perform(curl);
+
+ /* clean up the FTP commands list */
+ curl_slist_free_all(headerlist);
+ /* close the local file */
+ fclose(hd_src);
+
+ curl_easy_cleanup(curl);
curl_global_cleanup();
+
return res;
}