00001 #ifndef HEADER_CURL_MEMDEBUG_H
00002 #define HEADER_CURL_MEMDEBUG_H
00003 #ifdef CURLDEBUG
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #define CURL_MT_LOGFNAME_BUFSIZE 512
00032
00033 #define logfile curl_debuglogfile
00034
00035 extern FILE *logfile;
00036
00037
00038 CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source);
00039 CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line,
00040 const char *source);
00041 CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line,
00042 const char *source);
00043 CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source);
00044 CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source);
00045 #if defined(WIN32) && defined(UNICODE)
00046 CURL_EXTERN wchar_t *curl_dowcsdup(const wchar_t *str, int line,
00047 const char *source);
00048 #endif
00049
00050 CURL_EXTERN void curl_memdebug(const char *logname);
00051 CURL_EXTERN void curl_memlimit(long limit);
00052 CURL_EXTERN void curl_memlog(const char *format, ...);
00053
00054
00055 CURL_EXTERN curl_socket_t curl_socket(int domain, int type, int protocol,
00056 int line, const char *source);
00057 CURL_EXTERN void curl_mark_sclose(curl_socket_t sockfd,
00058 int line, const char *source);
00059 CURL_EXTERN int curl_sclose(curl_socket_t sockfd,
00060 int line, const char *source);
00061 CURL_EXTERN curl_socket_t curl_accept(curl_socket_t s, void *a, void *alen,
00062 int line, const char *source);
00063 #ifdef HAVE_SOCKETPAIR
00064 CURL_EXTERN int curl_socketpair(int domain, int type, int protocol,
00065 curl_socket_t socket_vector[2],
00066 int line, const char *source);
00067 #endif
00068
00069
00070 CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
00071 const char *source);
00072 #ifdef HAVE_FDOPEN
00073 CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line,
00074 const char *source);
00075 #endif
00076 CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
00077
00078 #ifndef MEMDEBUG_NODEFINES
00079
00080
00081 #undef strdup
00082 #define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
00083 #define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
00084 #define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
00085 #define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
00086 #define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
00087
00088 #ifdef WIN32
00089 # ifdef UNICODE
00090 # undef wcsdup
00091 # define wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
00092 # undef _wcsdup
00093 # define _wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
00094 # undef _tcsdup
00095 # define _tcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
00096 # else
00097 # undef _tcsdup
00098 # define _tcsdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
00099 # endif
00100 #endif
00101
00102 #undef socket
00103 #define socket(domain,type,protocol)\
00104 curl_socket(domain, type, protocol, __LINE__, __FILE__)
00105 #undef accept
00106 #define accept(sock,addr,len)\
00107 curl_accept(sock, addr, len, __LINE__, __FILE__)
00108 #ifdef HAVE_SOCKETPAIR
00109 #define socketpair(domain,type,protocol,socket_vector)\
00110 curl_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__)
00111 #endif
00112
00113 #ifdef HAVE_GETADDRINFO
00114 #if defined(getaddrinfo) && defined(__osf__)
00115
00116
00117
00118 #define ogetaddrinfo(host,serv,hint,res) \
00119 curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
00120 #else
00121 #undef getaddrinfo
00122 #define getaddrinfo(host,serv,hint,res) \
00123 curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
00124 #endif
00125 #endif
00126
00127 #ifdef HAVE_GETNAMEINFO
00128 #undef getnameinfo
00129 #define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
00130 curl_dogetnameinfo(sa, salen, host, hostlen, serv, servlen, flags, \
00131 __LINE__, __FILE__)
00132 #endif
00133
00134 #ifdef HAVE_FREEADDRINFO
00135 #undef freeaddrinfo
00136 #define freeaddrinfo(data) \
00137 curl_dofreeaddrinfo(data, __LINE__, __FILE__)
00138 #endif
00139
00140
00141 #undef sclose
00142 #define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
00143
00144 #define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__)
00145
00146 #undef fopen
00147 #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
00148 #undef fdopen
00149 #define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__)
00150 #define fclose(file) curl_fclose(file,__LINE__,__FILE__)
00151
00152 #endif
00153
00154 #endif
00155
00156
00157
00158
00159
00160 #ifndef fake_sclose
00161 #define fake_sclose(x) Curl_nop_stmt
00162 #endif
00163
00164
00165
00166
00167
00168
00169
00170 #define Curl_safefree(ptr) \
00171 do { free((ptr)); (ptr) = NULL;} WHILE_FALSE
00172
00173 #endif