first.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_LOCALE_H
00025 #  include <locale.h> /* for setlocale() */
00026 #endif
00027 
00028 #ifdef HAVE_IO_H
00029 #  include <io.h> /* for setmode() */
00030 #endif
00031 
00032 #ifdef HAVE_FCNTL_H
00033 #  include <fcntl.h> /* for setmode() */
00034 #endif
00035 
00036 #ifdef USE_NSS
00037 #include <nspr.h>
00038 #endif
00039 
00040 #ifdef CURLDEBUG
00041 #  define MEMDEBUG_NODEFINES
00042 #  include "memdebug.h"
00043 #endif
00044 
00045 int select_wrapper(int nfds, fd_set *rd, fd_set *wr, fd_set *exc,
00046                    struct timeval *tv)
00047 {
00048   if(nfds < 0) {
00049     SET_SOCKERRNO(EINVAL);
00050     return -1;
00051   }
00052 #ifdef USE_WINSOCK
00053   /*
00054    * Winsock select() requires that at least one of the three fd_set
00055    * pointers is not NULL and points to a non-empty fdset. IOW Winsock
00056    * select() can not be used to sleep without a single fd_set.
00057    */
00058   if(!nfds) {
00059     Sleep((1000*tv->tv_sec) + (DWORD)(((double)tv->tv_usec)/1000.0));
00060     return 0;
00061   }
00062 #endif
00063   return select(nfds, rd, wr, exc, tv);
00064 }
00065 
00066 void wait_ms(int ms)
00067 {
00068   struct timeval t;
00069   t.tv_sec = ms/1000;
00070   ms -= (int)t.tv_sec * 1000;
00071   t.tv_usec = ms * 1000;
00072   select_wrapper(0, NULL, NULL, NULL, &t);
00073 }
00074 
00075 char *libtest_arg2=NULL;
00076 char *libtest_arg3=NULL;
00077 int test_argc;
00078 char **test_argv;
00079 
00080 struct timeval tv_test_start; /* for test timing */
00081 
00082 #ifdef UNITTESTS
00083 int unitfail; /* for unittests */
00084 #endif
00085 
00086 #ifdef CURLDEBUG
00087 static void memory_tracking_init(void)
00088 {
00089   char *env;
00090   /* if CURL_MEMDEBUG is set, this starts memory tracking message logging */
00091   env = curl_getenv("CURL_MEMDEBUG");
00092   if(env) {
00093     /* use the value as file name */
00094     char fname[CURL_MT_LOGFNAME_BUFSIZE];
00095     if(strlen(env) >= CURL_MT_LOGFNAME_BUFSIZE)
00096       env[CURL_MT_LOGFNAME_BUFSIZE-1] = '\0';
00097     strcpy(fname, env);
00098     curl_free(env);
00099     curl_memdebug(fname);
00100     /* this weird stuff here is to make curl_free() get called
00101        before curl_memdebug() as otherwise memory tracking will
00102        log a free() without an alloc! */
00103   }
00104   /* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
00105   env = curl_getenv("CURL_MEMLIMIT");
00106   if(env) {
00107     char *endptr;
00108     long num = strtol(env, &endptr, 10);
00109     if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
00110       curl_memlimit(num);
00111     curl_free(env);
00112   }
00113 }
00114 #else
00115 #  define memory_tracking_init() Curl_nop_stmt
00116 #endif
00117 
00118 /* returns a hexdump in a static memory area */
00119 char *hexdump(unsigned char *buffer, size_t len)
00120 {
00121   static char dump[200*3+1];
00122   char *p = dump;
00123   size_t i;
00124   if(len > 200)
00125     return NULL;
00126   for(i=0; i<len; i++, p += 3)
00127     snprintf(p, 4, "%02x ", buffer[i]);
00128   return dump;
00129 }
00130 
00131 
00132 int main(int argc, char **argv)
00133 {
00134   char *URL;
00135   int result;
00136 
00137 #ifdef O_BINARY
00138 #  ifdef __HIGHC__
00139   _setmode(stdout, O_BINARY);
00140 #  else
00141   setmode(fileno(stdout), O_BINARY);
00142 #  endif
00143 #endif
00144 
00145   memory_tracking_init();
00146 
00147   /*
00148    * Setup proper locale from environment. This is needed to enable locale-
00149    * specific behaviour by the C library in order to test for undesired side
00150    * effects that could cause in libcurl.
00151    */
00152 #ifdef HAVE_SETLOCALE
00153   setlocale(LC_ALL, "");
00154 #endif
00155 
00156   if(argc< 2) {
00157     fprintf(stderr, "Pass URL as argument please\n");
00158     return 1;
00159   }
00160 
00161   test_argc = argc;
00162   test_argv = argv;
00163 
00164   if(argc>2)
00165     libtest_arg2=argv[2];
00166 
00167   if(argc>3)
00168     libtest_arg3=argv[3];
00169 
00170   URL = argv[1]; /* provide this to the rest */
00171 
00172   fprintf(stderr, "URL: %s\n", URL);
00173 
00174   result = test(URL);
00175 
00176 #ifdef USE_NSS
00177   if(PR_Initialized())
00178     /* prevent valgrind from reporting possibly lost memory (fd cache, ...) */
00179     PR_Cleanup();
00180 #endif
00181 
00182   return result;
00183 }


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