1#ifndef HEADER_CURL_MEMDEBUG_H 2#define HEADER_CURL_MEMDEBUG_H 3#ifdef CURLDEBUG 4/*************************************************************************** 5 * _ _ ____ _ 6 * Project ___| | | | _ \| | 7 * / __| | | | |_) | | 8 * | (__| |_| | _ <| |___ 9 * \___|\___/|_| \_\_____| 10 * 11 * Copyright (C) 1998 - 2011, 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 ***************************************************************************/ 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 31#include "setup.h" 32 33#include <curl/curl.h> 34 35#ifdef HAVE_SYS_SOCKET_H 36#include <sys/socket.h> 37#endif 38 39#define CURL_MT_LOGFNAME_BUFSIZE 512 40 41#define logfile curl_debuglogfile 42 43extern FILE *logfile; 44 45/* memory functions */ 46CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source); 47CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, 48 const char *source); 49CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, 50 const char *source); 51CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source); 52CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source); 53CURL_EXTERN void curl_memdebug(const char *logname); 54CURL_EXTERN void curl_memlimit(long limit); 55CURL_EXTERN void curl_memlog(const char *format, ...); 56 57/* file descriptor manipulators */ 58CURL_EXTERN curl_socket_t curl_socket(int domain, int type, int protocol, 59 int line , const char *source); 60CURL_EXTERN void curl_mark_sclose(curl_socket_t sockfd, 61 int line , const char *source); 62CURL_EXTERN int curl_sclose(curl_socket_t sockfd, 63 int line , const char *source); 64CURL_EXTERN curl_socket_t curl_accept(curl_socket_t s, void *a, void *alen, 65 int line, const char *source); 66#ifdef HAVE_SOCKETPAIR 67CURL_EXTERN int curl_socketpair(int domain, int type, int protocol, 68 curl_socket_t socket_vector[2], 69 int line , const char *source); 70#endif 71 72/* FILE functions */ 73CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line, 74 const char *source); 75#ifdef HAVE_FDOPEN 76CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line, 77 const char *source); 78#endif 79CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source); 80 81#ifndef MEMDEBUG_NODEFINES 82 83/* Set this symbol on the command-line, recompile all lib-sources */ 84#undef strdup 85#define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__) 86#define malloc(size) curl_domalloc(size, __LINE__, __FILE__) 87#define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__) 88#define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__) 89#define free(ptr) curl_dofree(ptr, __LINE__, __FILE__) 90 91#define socket(domain,type,protocol)\ 92 curl_socket(domain,type,protocol,__LINE__,__FILE__) 93#undef accept /* for those with accept as a macro */ 94#define accept(sock,addr,len)\ 95 curl_accept(sock,addr,len,__LINE__,__FILE__) 96#ifdef HAVE_SOCKETPAIR 97#define socketpair(domain,type,protocol,socket_vector)\ 98 curl_socketpair(domain,type,protocol,socket_vector,__LINE__,__FILE__) 99#endif 100 101#ifdef HAVE_GETADDRINFO 102#if defined(getaddrinfo) && defined(__osf__) 103/* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define 104 our macro as for other platforms. Instead, we redefine the new name they 105 define getaddrinfo to become! */ 106#define ogetaddrinfo(host,serv,hint,res) \ 107 curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__) 108#else 109#undef getaddrinfo 110#define getaddrinfo(host,serv,hint,res) \ 111 curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__) 112#endif 113#endif /* HAVE_GETADDRINFO */ 114 115#ifdef HAVE_GETNAMEINFO 116#undef getnameinfo 117#define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \ 118 curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \ 119 __FILE__) 120#endif /* HAVE_GETNAMEINFO */ 121 122#ifdef HAVE_FREEADDRINFO 123#undef freeaddrinfo 124#define freeaddrinfo(data) \ 125 curl_dofreeaddrinfo(data,__LINE__,__FILE__) 126#endif /* HAVE_FREEADDRINFO */ 127 128/* sclose is probably already defined, redefine it! */ 129#undef sclose 130#define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__) 131 132#define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__) 133 134#undef fopen 135#define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__) 136#undef fdopen 137#define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__) 138#define fclose(file) curl_fclose(file,__LINE__,__FILE__) 139 140#endif /* MEMDEBUG_NODEFINES */ 141 142#endif /* CURLDEBUG */ 143 144/* 145** Following section applies even when CURLDEBUG is not defined. 146*/ 147 148#ifndef fake_sclose 149#define fake_sclose(x) Curl_nop_stmt 150#endif 151 152/* 153 * Curl_safefree defined as a macro to allow MemoryTracking feature 154 * to log free() calls at same location where Curl_safefree is used. 155 * This macro also assigns NULL to given pointer when free'd. 156 */ 157 158#define Curl_safefree(ptr) \ 159 do {if((ptr)) {free((ptr)); (ptr) = NULL;}} WHILE_FALSE 160 161#endif /* HEADER_CURL_MEMDEBUG_H */ 162