Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "test.h"
00023
00024 #ifdef HAVE_FCNTL_H
00025 #include <fcntl.h>
00026 #endif
00027
00028 #include "memdebug.h"
00029
00030
00031
00032
00033
00034 int test(char *URL)
00035 {
00036 CURL *curl;
00037 CURLcode res = CURLE_OK;
00038 FILE *hd_src;
00039 int hd;
00040 struct_stat file_info;
00041 int error;
00042
00043 if(!libtest_arg2) {
00044 fprintf(stderr, "Usage: <url> <file-to-upload>\n");
00045 return TEST_ERR_USAGE;
00046 }
00047
00048 hd_src = fopen(libtest_arg2, "rb");
00049 if(NULL == hd_src) {
00050 error = ERRNO;
00051 fprintf(stderr, "fopen failed with error: %d %s\n",
00052 error, strerror(error));
00053 fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
00054 return -2;
00055 }
00056
00057
00058 hd = fstat(fileno(hd_src), &file_info);
00059 if(hd == -1) {
00060
00061 error = ERRNO;
00062 fprintf(stderr, "fstat() failed with error: %d %s\n",
00063 error, strerror(error));
00064 fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
00065 fclose(hd_src);
00066 return TEST_ERR_MAJOR_BAD;
00067 }
00068
00069 if(! file_info.st_size) {
00070 fprintf(stderr, "ERROR: file %s has zero size!\n", libtest_arg2);
00071 fclose(hd_src);
00072 return TEST_ERR_MAJOR_BAD;
00073 }
00074
00075 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00076 fprintf(stderr, "curl_global_init() failed\n");
00077 fclose(hd_src);
00078 return TEST_ERR_MAJOR_BAD;
00079 }
00080
00081
00082 curl = curl_easy_init();
00083 if(!curl) {
00084 fprintf(stderr, "curl_easy_init() failed\n");
00085 curl_global_cleanup();
00086 fclose(hd_src);
00087 return TEST_ERR_MAJOR_BAD;
00088 }
00089
00090
00091 test_setopt(curl, CURLOPT_UPLOAD, 1L);
00092
00093
00094 test_setopt(curl, CURLOPT_VERBOSE, 1L);
00095
00096
00097 test_setopt(curl, CURLOPT_URL, URL);
00098
00099
00100 test_setopt(curl, CURLOPT_READDATA, hd_src);
00101
00102
00103 res = curl_easy_perform(curl);
00104
00105
00106
00107 res = curl_easy_perform(curl);
00108
00109 test_cleanup:
00110
00111
00112 fclose(hd_src);
00113
00114 curl_easy_cleanup(curl);
00115 curl_global_cleanup();
00116
00117 return res;
00118 }