lib541.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
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  * Two FTP uploads, the second with no content sent.
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; /* if this happens things are major weird */
00055   }
00056 
00057   /* get the file size of the local file */
00058   hd = fstat(fileno(hd_src), &file_info);
00059   if(hd == -1) {
00060     /* can't open file, bail out */
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   /* get a curl handle */
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   /* enable uploading */
00091   test_setopt(curl, CURLOPT_UPLOAD, 1L);
00092 
00093   /* enable verbose */
00094   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00095 
00096   /* specify target */
00097   test_setopt(curl, CURLOPT_URL, URL);
00098 
00099   /* now specify which file to upload */
00100   test_setopt(curl, CURLOPT_READDATA, hd_src);
00101 
00102   /* Now run off and do what you've been told! */
00103   res = curl_easy_perform(curl);
00104 
00105   /* and now upload the exact same again, but without rewinding so it already
00106      is at end of file */
00107   res = curl_easy_perform(curl);
00108 
00109 test_cleanup:
00110 
00111   /* close the local file */
00112   fclose(hd_src);
00113 
00114   curl_easy_cleanup(curl);
00115   curl_global_cleanup();
00116 
00117   return res;
00118 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05