first.c 2.0 KB

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