1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
30 #define TEST_HANG_TIMEOUT 60 * 1000
39 struct_stat file_info;
48 fprintf(stderr, "Usage: lib529 [url] [uploadfile]\n");
51 fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
53 return TEST_ERR_USAGE;
56 hd_src = fopen(libtest_arg2, "rb");
59 fprintf(stderr, "fopen() failed with error: %d (%s)\n",
60 error, strerror(error));
61 fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
62 return TEST_ERR_FOPEN;
65 /* get the file size of the local file */
66 hd = fstat(fileno(hd_src), &file_info);
68 /* can't open file, bail out */
70 fprintf(stderr, "fstat() failed with error: %d (%s)\n",
71 error, strerror(error));
72 fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
74 return TEST_ERR_FSTAT;
77 res_global_init(CURL_GLOBAL_ALL);
85 /* enable uploading */
86 easy_setopt(curl, CURLOPT_UPLOAD, 1L);
89 easy_setopt(curl,CURLOPT_URL, URL);
92 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
95 easy_setopt(curl, CURLOPT_FTPPORT, "-");
97 /* now specify which file to upload */
98 easy_setopt(curl, CURLOPT_READDATA, hd_src);
100 /* NOTE: if you want this code to work on Windows with libcurl as a DLL, you
101 MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to
102 do so will give you a crash since a DLL may not use the variable's memory
103 when passed in to it from an app like this. */
105 /* Set the size of the file to upload (optional). If you give a *_LARGE
106 option you MUST make sure that the type of the passed-in argument is a
107 curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
108 make sure that to pass in a type 'long' argument. */
109 easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
113 multi_add_handle(m, curl);
116 struct timeval interval;
121 interval.tv_usec = 0;
123 multi_perform(m, &running);
125 abort_on_test_timeout();
134 multi_fdset(m, &rd, &wr, &exc, &maxfd);
136 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
138 select_test(maxfd+1, &rd, &wr, &exc, &interval);
140 abort_on_test_timeout();
147 /* proper cleanup sequence - type PA */
148 curl_multi_remove_handle(m, curl);
149 curl_multi_cleanup(m);
150 curl_easy_cleanup(curl);
151 curl_global_cleanup();
154 /* proper cleanup sequence - type PB */
155 curl_multi_remove_handle(m, curl);
156 curl_easy_cleanup(curl);
157 curl_multi_cleanup(m);
158 curl_global_cleanup();
161 /* close the local file */