2 #ifndef _CURL_MEMDEBUG_H
3 #define _CURL_MEMDEBUG_H
4 /***************************************************************************
6 * Project ___| | | | _ \| |
8 * | (__| |_| | _ <| |___
9 * \___|\___/|_| \_\_____|
11 * Copyright (C) 1998 - 2009, 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 http://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.
25 ***************************************************************************/
28 * CAUTION: this header is designed to work when included by the app-side
29 * as well as the library. Do not mix with library internals!
34 #include <curl/curl.h>
36 #ifdef HAVE_SYS_TYPES_H
37 #include <sys/types.h>
40 #ifdef HAVE_SYS_SOCKET_H
41 #include <sys/socket.h>
45 #define logfile curl_debuglogfile
49 /* memory functions */
50 CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source);
51 CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, const char *source);
52 CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, const char *source);
53 CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source);
54 CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source);
55 CURL_EXTERN void curl_memdebug(const char *logname);
56 CURL_EXTERN void curl_memlimit(long limit);
58 /* file descriptor manipulators */
59 CURL_EXTERN int curl_socket(int domain, int type, int protocol, int line , const char *);
60 CURL_EXTERN int curl_mark_sclose(int sockfd, int, const char *source);
61 CURL_EXTERN int curl_sclose(int sockfd, int, const char *source);
62 CURL_EXTERN int curl_accept(int s, void *addr, void *addrlen,
63 int line, const char *source);
66 CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
69 CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line,
72 CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
74 #ifndef MEMDEBUG_NODEFINES
76 /* Set this symbol on the command-line, recompile all lib-sources */
78 #define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
79 #define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
80 #define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
81 #define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
82 #define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
84 #define socket(domain,type,protocol)\
85 curl_socket(domain,type,protocol,__LINE__,__FILE__)
86 #undef accept /* for those with accept as a macro */
87 #define accept(sock,addr,len)\
88 curl_accept(sock,addr,len,__LINE__,__FILE__)
90 #ifdef HAVE_GETADDRINFO
91 #if defined(getaddrinfo) && defined(__osf__)
92 /* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define
93 our macro as for other platforms. Instead, we redefine the new name they
94 define getaddrinfo to become! */
95 #define ogetaddrinfo(host,serv,hint,res) \
96 curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
99 #define getaddrinfo(host,serv,hint,res) \
100 curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
102 #endif /* HAVE_GETADDRINFO */
104 #ifdef HAVE_GETNAMEINFO
106 #define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \
107 curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \
109 #endif /* HAVE_GETNAMEINFO */
111 #ifdef HAVE_FREEADDRINFO
113 #define freeaddrinfo(data) \
114 curl_dofreeaddrinfo(data,__LINE__,__FILE__)
115 #endif /* HAVE_FREEADDRINFO */
117 /* sclose is probably already defined, redefine it! */
119 #define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
121 #define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__)
124 #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
126 #define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__)
127 #define fclose(file) curl_fclose(file,__LINE__,__FILE__)
129 #endif /* MEMDEBUG_NODEFINES */
131 #endif /* _CURL_MEMDEBUG_H */
132 #endif /* CURLDEBUG */
135 #define fake_sclose(x)