49
hd_src = fopen(libtest_arg2, "rb");
52
fprintf(stderr, "fopen() failed with error: %d %s\n",
53
error, strerror(error));
54
fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
55
return -2; /* if this happens things are major weird */
51
58
/* get the file size of the local file */
52
hd = stat(libtest_arg2, &file_info);
59
hd = fstat(fileno(hd_src), &file_info);
54
61
/* can't open file, bail out */
56
fprintf(stderr, "stat() failed with error: %d %s\n",
63
fprintf(stderr, "fstat() failed with error: %d %s\n",
57
64
error, strerror(error));
58
fprintf(stderr, "WARNING: cannot open file %s\n", libtest_arg2);
65
fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2);
62
70
if(! file_info.st_size) {
63
fprintf(stderr, "WARNING: file %s has no size!\n", libtest_arg2);
71
fprintf(stderr, "ERROR: file %s has zero size!\n", libtest_arg2);
67
/* get a FILE * of the same file, could also be made with
68
fdopen() from the previous descriptor, but hey this is just
70
hd_src = fopen(libtest_arg2, "rb");
73
fprintf(stderr, "fopen() failed with error: %d %s\n",
74
error, strerror(error));
75
fprintf(stderr, "Error opening file: %s\n", libtest_arg2);
76
return -2; /* if this happens things are major weird */
79
76
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
80
77
fprintf(stderr, "curl_global_init() failed\n");
93
90
/* enable uploading */
94
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
91
test_setopt(curl, CURLOPT_UPLOAD, 1L);
96
93
/* enable verbose */
97
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
94
test_setopt(curl, CURLOPT_VERBOSE, 1L);
99
96
/* specify target */
100
curl_easy_setopt(curl,CURLOPT_URL, URL);
97
test_setopt(curl,CURLOPT_URL, URL);
102
99
/* now specify which file to upload */
103
curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
100
test_setopt(curl, CURLOPT_INFILE, hd_src);
105
102
/* Now run off and do what you've been told! */
106
103
res = curl_easy_perform(curl);