1 #ifndef HEADER_CURL_MEMDEBUG_H
2 #define HEADER_CURL_MEMDEBUG_H
4 /***************************************************************************
6 * Project ___| | | | _ \| |
8 * | (__| |_| | _ <| |___
9 * \___|\___/|_| \_\_____|
11 * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
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 https://curl.haxx.se/docs/copyright.html.
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.
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
24 ***************************************************************************/
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!
31 #define CURL_MT_LOGFNAME_BUFSIZE 512
33 #define logfile curl_debuglogfile
37 /* memory functions */
38 CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source);
39 CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line,
41 CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line,
43 CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source);
44 CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source);
45 #if defined(WIN32) && defined(UNICODE)
46 CURL_EXTERN wchar_t *curl_dowcsdup(const wchar_t *str, int line,
50 CURL_EXTERN void curl_memdebug(const char *logname);
51 CURL_EXTERN void curl_memlimit(long limit);
52 CURL_EXTERN void curl_memlog(const char *format, ...);
54 /* file descriptor manipulators */
55 CURL_EXTERN curl_socket_t curl_socket(int domain, int type, int protocol,
56 int line, const char *source);
57 CURL_EXTERN void curl_mark_sclose(curl_socket_t sockfd,
58 int line, const char *source);
59 CURL_EXTERN int curl_sclose(curl_socket_t sockfd,
60 int line, const char *source);
61 CURL_EXTERN curl_socket_t curl_accept(curl_socket_t s, void *a, void *alen,
62 int line, const char *source);
63 #ifdef HAVE_SOCKETPAIR
64 CURL_EXTERN int curl_socketpair(int domain, int type, int protocol,
65 curl_socket_t socket_vector[2],
66 int line, const char *source);
70 CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
73 CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line,
76 CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
78 #ifndef MEMDEBUG_NODEFINES
80 /* Set this symbol on the command-line, recompile all lib-sources */
82 #define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
83 #define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
84 #define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
85 #define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
86 #define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
91 # define wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
93 # define _wcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
95 # define _tcsdup(ptr) curl_dowcsdup(ptr, __LINE__, __FILE__)
98 # define _tcsdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
103 #define socket(domain,type,protocol)\
104 curl_socket(domain, type, protocol, __LINE__, __FILE__)
105 #undef accept /* for those with accept as a macro */
106 #define accept(sock,addr,len)\
107 curl_accept(sock, addr, len, __LINE__, __FILE__)
108 #ifdef HAVE_SOCKETPAIR
109 #define socketpair(domain,type,protocol,socket_vector)\
110 curl_socketpair(domain, type, protocol, socket_vector, __LINE__, __FILE__)
113 #ifdef HAVE_GETADDRINFO
114 #if defined(getaddrinfo) && defined(__osf__)
115 /* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define
116 our macro as for other platforms. Instead, we redefine the new name they
117 define getaddrinfo to become! */
118 #define ogetaddrinfo(host,serv,hint,res) \
119 curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
122 #define getaddrinfo(host,serv,hint,res) \
123 curl_dogetaddrinfo(host, serv, hint, res, __LINE__, __FILE__)
125 #endif /* HAVE_GETADDRINFO */
127 #ifdef HAVE_GETNAMEINFO
129 #define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
130 curl_dogetnameinfo(sa, salen, host, hostlen, serv, servlen, flags, \
132 #endif /* HAVE_GETNAMEINFO */
134 #ifdef HAVE_FREEADDRINFO
136 #define freeaddrinfo(data) \
137 curl_dofreeaddrinfo(data, __LINE__, __FILE__)
138 #endif /* HAVE_FREEADDRINFO */
140 /* sclose is probably already defined, redefine it! */
142 #define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
144 #define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__)
147 #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
149 #define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__)
150 #define fclose(file) curl_fclose(file,__LINE__,__FILE__)
152 #endif /* MEMDEBUG_NODEFINES */
154 #endif /* CURLDEBUG */
157 ** Following section applies even when CURLDEBUG is not defined.
161 #define fake_sclose(x) Curl_nop_stmt
165 * Curl_safefree defined as a macro to allow MemoryTracking feature
166 * to log free() calls at same location where Curl_safefree is used.
167 * This macro also assigns NULL to given pointer when free'd.
170 #define Curl_safefree(ptr) \
171 do { free((ptr)); (ptr) = NULL;} WHILE_FALSE
173 #endif /* HEADER_CURL_MEMDEBUG_H */