Git init
[external/curl.git] / tests / libtest / first.c
1 /*****************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  */
9
10 #include "test.h"
11
12 #ifdef HAVE_LOCALE_H
13 #include <locale.h> /* for setlocale() */
14 #endif
15
16 #ifdef CURLDEBUG
17 #  define MEMDEBUG_NODEFINES
18 #  include "memdebug.h"
19 #endif
20
21 int select_test (int num_fds, fd_set *rd, fd_set *wr, fd_set *exc,
22                  struct timeval *tv)
23 {
24 #ifdef USE_WINSOCK
25   /* Winsock doesn't like no socket set in 'rd', 'wr' or 'exc'. This is
26    * case when 'num_fds <= 0. So sleep.
27    */
28   if (num_fds <= 0) {
29     Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
30     return 0;
31   }
32 #endif
33   return select(num_fds, rd, wr, exc, tv);
34 }
35
36 char *libtest_arg2=NULL;
37 char *libtest_arg3=NULL;
38 int test_argc;
39 char **test_argv;
40
41
42 int main(int argc, char **argv)
43 {
44   char *URL;
45
46 #ifdef CURLDEBUG
47   /* this sends all memory debug messages to a logfile named memdump */
48   char *env = curl_getenv("CURL_MEMDEBUG");
49   if(env) {
50     /* use the value as file name */
51     char *s = strdup(env);
52     curl_free(env);
53     curl_memdebug(s);
54     free(s);
55     /* this weird strdup() and stuff here is to make the curl_free() get
56        called before the memdebug() as otherwise the memdebug tracing will
57        with tracing a free() without an alloc! */
58   }
59   /* this enables the fail-on-alloc-number-N functionality */
60   env = curl_getenv("CURL_MEMLIMIT");
61   if(env) {
62     char *endptr;
63     long num = strtol(env, &endptr, 10);
64     if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
65       curl_memlimit(num);
66     curl_free(env);
67   }
68 #endif
69
70   /*
71    * Setup proper locale from environment. This is needed to enable locale-
72    * specific behaviour by the C library in order to test for undesired side
73    * effects that could cause in libcurl.
74    */
75 #ifdef HAVE_SETLOCALE
76   setlocale(LC_ALL, "");
77 #endif
78
79   if(argc< 2 ) {
80     fprintf(stderr, "Pass URL as argument please\n");
81     return 1;
82   }
83
84   test_argc = argc;
85   test_argv = argv;
86
87   if(argc>2)
88     libtest_arg2=argv[2];
89
90   if(argc>3)
91     libtest_arg3=argv[3];
92
93   URL = argv[1]; /* provide this to the rest */
94
95   fprintf(stderr, "URL: %s\n", URL);
96
97   return test(URL);
98 }