1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2017, 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 https://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
38 struct_stat file_info;
47 fprintf(stderr, "Usage: lib529 [url] [uploadfile]\n");
50 fprintf(stderr, "Usage: lib525 [url] [uploadfile]\n");
52 return TEST_ERR_USAGE;
55 hd_src = fopen(libtest_arg2, "rb");
57 fprintf(stderr, "fopen failed with error: %d (%s)\n",
58 errno, strerror(errno));
59 fprintf(stderr, "Error opening file: (%s)\n", libtest_arg2);
60 return TEST_ERR_FOPEN;
63 /* get the file size of the local file */
64 hd = fstat(fileno(hd_src), &file_info);
66 /* can't open file, bail out */
67 fprintf(stderr, "fstat() failed with error: %d (%s)\n",
68 errno, strerror(errno));
69 fprintf(stderr, "ERROR: cannot open file (%s)\n", libtest_arg2);
71 return TEST_ERR_FSTAT;
74 res_global_init(CURL_GLOBAL_ALL);
82 /* enable uploading */
83 easy_setopt(curl, CURLOPT_UPLOAD, 1L);
86 easy_setopt(curl, CURLOPT_URL, URL);
89 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
92 easy_setopt(curl, CURLOPT_FTPPORT, "-");
94 /* now specify which file to upload */
95 easy_setopt(curl, CURLOPT_READDATA, hd_src);
97 /* NOTE: if you want this code to work on Windows with libcurl as a DLL, you
98 MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to
99 do so will give you a crash since a DLL may not use the variable's memory
100 when passed in to it from an app like this. */
102 /* Set the size of the file to upload (optional). If you give a *_LARGE
103 option you MUST make sure that the type of the passed-in argument is a
104 curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
105 make sure that to pass in a type 'long' argument. */
106 easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
110 multi_add_handle(m, curl);
113 struct timeval interval;
118 interval.tv_usec = 0;
120 multi_perform(m, &running);
122 abort_on_test_timeout();
131 multi_fdset(m, &rd, &wr, &exc, &maxfd);
133 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
135 select_test(maxfd + 1, &rd, &wr, &exc, &interval);
137 abort_on_test_timeout();
144 /* proper cleanup sequence - type PA */
145 curl_multi_remove_handle(m, curl);
146 curl_multi_cleanup(m);
147 curl_easy_cleanup(curl);
148 curl_global_cleanup();
151 /* proper cleanup sequence - type PB */
152 curl_multi_remove_handle(m, curl);
153 curl_easy_cleanup(curl);
154 curl_multi_cleanup(m);
155 curl_global_cleanup();
158 /* close the local file */