sourcemod/extensions/curl/curl-src/tests/libtest/first.c

83 lines
1.9 KiB
C
Raw Normal View History

2013-03-18 01:55:59 +01:00
/*****************************************************************************
2009-01-09 00:31:00 +01:00
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
2013-03-18 01:55:59 +01:00
* $Id: first.c,v 1.19 2008-09-20 04:26:55 yangtse Exp $
*/
2009-01-09 00:31:00 +01:00
2013-03-18 01:55:59 +01:00
#include "test.h"
2013-03-17 23:23:20 +01:00
2009-01-09 00:31:00 +01:00
#ifdef CURLDEBUG
# define MEMDEBUG_NODEFINES
# include "memdebug.h"
#endif
2013-03-18 01:55:59 +01:00
int select_test (int num_fds, fd_set *rd, fd_set *wr, fd_set *exc,
struct timeval *tv)
2009-01-09 00:31:00 +01:00
{
#ifdef USE_WINSOCK
2013-03-18 01:55:59 +01:00
/* Winsock doesn't like no socket set in 'rd', 'wr' or 'exc'. This is
* case when 'num_fds <= 0. So sleep.
2009-01-09 00:31:00 +01:00
*/
2013-03-18 01:55:59 +01:00
if (num_fds <= 0) {
2009-01-09 00:31:00 +01:00
Sleep(1000*tv->tv_sec + tv->tv_usec/1000);
return 0;
}
#endif
2013-03-18 01:55:59 +01:00
return select(num_fds, rd, wr, exc, tv);
2009-01-09 00:31:00 +01:00
}
char *libtest_arg2=NULL;
char *libtest_arg3=NULL;
int test_argc;
char **test_argv;
2013-03-18 01:55:59 +01:00
int main(int argc, char **argv)
{
char *URL;
2009-01-09 00:31:00 +01:00
#ifdef CURLDEBUG
2013-03-18 01:55:59 +01:00
/* this sends all memory debug messages to a logfile named memdump */
char *env = curl_getenv("CURL_MEMDEBUG");
2009-01-09 00:31:00 +01:00
if(env) {
/* use the value as file name */
2013-03-18 01:55:59 +01:00
char *s = strdup(env);
2009-01-09 00:31:00 +01:00
curl_free(env);
2013-03-18 01:55:59 +01:00
curl_memdebug(s);
free(s);
/* this weird strdup() and stuff here is to make the curl_free() get
called before the memdebug() as otherwise the memdebug tracing will
with tracing a free() without an alloc! */
2009-01-09 00:31:00 +01:00
}
2013-03-18 01:55:59 +01:00
/* this enables the fail-on-alloc-number-N functionality */
2009-01-09 00:31:00 +01:00
env = curl_getenv("CURL_MEMLIMIT");
if(env) {
2013-03-18 01:55:59 +01:00
curl_memlimit(atoi(env));
2009-01-09 00:31:00 +01:00
curl_free(env);
}
#endif
if(argc< 2 ) {
fprintf(stderr, "Pass URL as argument please\n");
return 1;
}
test_argc = argc;
test_argv = argv;
if(argc>2)
libtest_arg2=argv[2];
if(argc>3)
libtest_arg3=argv[3];
URL = argv[1]; /* provide this to the rest */
fprintf(stderr, "URL: %s\n", URL);
return test(URL);
}