Cygwin preprocessor adjustments
[platform/upstream/curl.git] / tests / libtest / first.c
1 #include "test.h"
2
3 #ifdef CURLDEBUG
4 /* provide a proto for this debug function */
5 extern void curl_memdebug(const char *);
6 extern void curl_memlimit(int);
7 #endif
8
9 /* test is provided in the test code file */
10 int test(char *url);
11
12 int select_test (int num_fds, fd_set *rd, fd_set *wr, fd_set *exc,
13                  struct timeval *tv)
14 {
15 #if defined(WIN32) && !defined(__CYGWIN__)
16   /* Winsock doesn't like no socket set in 'rd', 'wr' or 'exc'. This is
17    * case when 'num_fds <= 0. So sleep.
18    */
19   if (num_fds <= 0) {
20     Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
21     return 0;
22   }
23 #endif
24   return select(num_fds, rd, wr, exc, tv);
25 }
26
27 char *arg2=NULL;
28
29 int main(int argc, char **argv)
30 {
31   char *URL;
32
33 #ifdef CURLDEBUG
34   /* this sends all memory debug messages to a logfile named memdump */
35   char *env = curl_getenv("CURL_MEMDEBUG");
36   if(env) {
37     /* use the value as file name */
38     char *s = strdup(env);
39     curl_free(env);
40     curl_memdebug(s);
41     free(s);
42     /* this weird strdup() and stuff here is to make the curl_free() get
43        called before the memdebug() as otherwise the memdebug tracing will
44        with tracing a free() without an alloc! */
45   }
46   /* this enables the fail-on-alloc-number-N functionality */
47   env = curl_getenv("CURL_MEMLIMIT");
48   if(env) {
49     curl_memlimit(atoi(env));
50     curl_free(env);
51   }
52 #endif
53   if(argc< 2 ) {
54     fprintf(stderr, "Pass URL as argument please\n");
55     return 1;
56   }
57   if(argc>2)
58     arg2=argv[2];
59
60   URL = argv[1]; /* provide this to the rest */
61
62   fprintf(stderr, "URL: %s\n", URL);
63
64   return test(URL);
65 }