memdebug.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifdef CURLDEBUG
  2. #ifndef _CURL_MEDEBUG_H
  3. #define _CURL_MEDEBUG_H
  4. /***************************************************************************
  5. * _ _ ____ _
  6. * Project ___| | | | _ \| |
  7. * / __| | | | |_) | |
  8. * | (__| |_| | _ <| |___
  9. * \___|\___/|_| \_\_____|
  10. *
  11. * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  12. *
  13. * This software is licensed as described in the file COPYING, which
  14. * you should have received as part of this distribution. The terms
  15. * are also available at http://curl.haxx.se/docs/copyright.html.
  16. *
  17. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  18. * copies of the Software, and permit persons to whom the Software is
  19. * furnished to do so, under the terms of the COPYING file.
  20. *
  21. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  22. * KIND, either express or implied.
  23. *
  24. * $Id$
  25. ***************************************************************************/
  26. /*
  27. * CAUTION: this header is designed to work when included by the app-side
  28. * as well as the library. Do not mix with library internals!
  29. */
  30. #include "setup.h"
  31. #include <curl/curl.h>
  32. #ifdef HAVE_SYS_TYPES_H
  33. #include <sys/types.h>
  34. #endif
  35. #ifdef HAVE_SYS_SOCKET_H
  36. #include <sys/socket.h>
  37. #endif
  38. #include <stdio.h>
  39. #ifdef HAVE_MEMORY_H
  40. #include <memory.h>
  41. #endif
  42. #define logfile curl_debuglogfile
  43. extern FILE *logfile;
  44. /* memory functions */
  45. CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source);
  46. CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, const char *source);
  47. CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, const char *source);
  48. CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source);
  49. CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source);
  50. CURL_EXTERN void curl_memdebug(const char *logname);
  51. CURL_EXTERN void curl_memlimit(long limit);
  52. /* file descriptor manipulators */
  53. CURL_EXTERN int curl_socket(int domain, int type, int protocol, int line , const char *);
  54. CURL_EXTERN int curl_sclose(int sockfd, int, const char *source);
  55. CURL_EXTERN int curl_accept(int s, void *addr, void *addrlen,
  56. int line, const char *source);
  57. /* FILE functions */
  58. CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
  59. const char *source);
  60. CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
  61. #ifndef MEMDEBUG_NODEFINES
  62. /* Set this symbol on the command-line, recompile all lib-sources */
  63. #undef strdup
  64. #define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
  65. #define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
  66. #define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
  67. #define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
  68. #define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
  69. #define socket(domain,type,protocol)\
  70. curl_socket(domain,type,protocol,__LINE__,__FILE__)
  71. #undef accept /* for those with accept as a macro */
  72. #define accept(sock,addr,len)\
  73. curl_accept(sock,addr,len,__LINE__,__FILE__)
  74. #if defined(getaddrinfo) && defined(__osf__)
  75. /* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define
  76. our macro as for other platforms. Instead, we redefine the new name they
  77. define getaddrinfo to become! */
  78. #define ogetaddrinfo(host,serv,hint,res) \
  79. curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
  80. #else
  81. #undef getaddrinfo
  82. #define getaddrinfo(host,serv,hint,res) \
  83. curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
  84. #endif
  85. #ifdef HAVE_GETNAMEINFO
  86. #undef getnameinfo
  87. #define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
  88. curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \
  89. __FILE__)
  90. #endif
  91. #undef freeaddrinfo
  92. #define freeaddrinfo(data) \
  93. curl_dofreeaddrinfo(data,__LINE__,__FILE__)
  94. /* sclose is probably already defined, redefine it! */
  95. #undef sclose
  96. #define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
  97. /* ares-adjusted define: */
  98. #undef closesocket
  99. #define closesocket(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
  100. #undef fopen
  101. #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
  102. #define fclose(file) curl_fclose(file,__LINE__,__FILE__)
  103. #endif /* MEMDEBUG_NODEFINES */
  104. #endif /* _CURL_MEDEBUG_H */
  105. #endif /* CURLDEBUG */