memdebug.h revision 5ab5018bf8f0e39957d264f33c3eeddd958ed5d8
1#ifdef CURLDEBUG 2#ifndef _CURL_MEMDEBUG_H 3#define _CURL_MEMDEBUG_H 4/*************************************************************************** 5 * _ _ ____ _ 6 * Project ___| | | | _ \| | 7 * / __| | | | |_) | | 8 * | (__| |_| | _ <| |___ 9 * \___|\___/|_| \_\_____| 10 * 11 * Copyright (C) 1998 - 2010, 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_TYPES_H 36#include <sys/types.h> 37#endif 38 39#ifdef HAVE_SYS_SOCKET_H 40#include <sys/socket.h> 41#endif 42#include <stdio.h> 43 44#define logfile curl_debuglogfile 45 46extern FILE *logfile; 47 48/* memory functions */ 49CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source); 50CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, const char *source); 51CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, const char *source); 52CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source); 53CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source); 54CURL_EXTERN void curl_memdebug(const char *logname); 55CURL_EXTERN void curl_memlimit(long limit); 56CURL_EXTERN void curl_memlog(const char *format, ...); 57 58/* file descriptor manipulators */ 59CURL_EXTERN curl_socket_t curl_socket(int domain, int type, int protocol, 60 int line , const char *source); 61CURL_EXTERN void curl_mark_sclose(curl_socket_t sockfd, 62 int line , const char *source); 63CURL_EXTERN int curl_sclose(curl_socket_t sockfd, 64 int line , const char *source); 65CURL_EXTERN curl_socket_t curl_accept(curl_socket_t s, void *a, void *alen, 66 int line, const char *source); 67 68/* FILE functions */ 69CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line, 70 const char *source); 71#ifdef HAVE_FDOPEN 72CURL_EXTERN FILE *curl_fdopen(int filedes, const char *mode, int line, 73 const char *source); 74#endif 75CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source); 76 77#ifndef MEMDEBUG_NODEFINES 78 79/* Set this symbol on the command-line, recompile all lib-sources */ 80#undef strdup 81#define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__) 82#define malloc(size) curl_domalloc(size, __LINE__, __FILE__) 83#define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__) 84#define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__) 85#define free(ptr) curl_dofree(ptr, __LINE__, __FILE__) 86 87#define socket(domain,type,protocol)\ 88 curl_socket(domain,type,protocol,__LINE__,__FILE__) 89#undef accept /* for those with accept as a macro */ 90#define accept(sock,addr,len)\ 91 curl_accept(sock,addr,len,__LINE__,__FILE__) 92 93#ifdef HAVE_GETADDRINFO 94#if defined(getaddrinfo) && defined(__osf__) 95/* OSF/1 and Tru64 have getaddrinfo as a define already, so we cannot define 96 our macro as for other platforms. Instead, we redefine the new name they 97 define getaddrinfo to become! */ 98#define ogetaddrinfo(host,serv,hint,res) \ 99 curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__) 100#else 101#undef getaddrinfo 102#define getaddrinfo(host,serv,hint,res) \ 103 curl_dogetaddrinfo(host,serv,hint,res,__LINE__,__FILE__) 104#endif 105#endif /* HAVE_GETADDRINFO */ 106 107#ifdef HAVE_GETNAMEINFO 108#undef getnameinfo 109#define getnameinfo(sa,salen,host,hostlen,serv,servlen,flags) \ 110 curl_dogetnameinfo(sa,salen,host,hostlen,serv,servlen,flags, __LINE__, \ 111 __FILE__) 112#endif /* HAVE_GETNAMEINFO */ 113 114#ifdef HAVE_FREEADDRINFO 115#undef freeaddrinfo 116#define freeaddrinfo(data) \ 117 curl_dofreeaddrinfo(data,__LINE__,__FILE__) 118#endif /* HAVE_FREEADDRINFO */ 119 120/* sclose is probably already defined, redefine it! */ 121#undef sclose 122#define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__) 123 124#define fake_sclose(sockfd) curl_mark_sclose(sockfd,__LINE__,__FILE__) 125 126#undef fopen 127#define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__) 128#undef fdopen 129#define fdopen(file,mode) curl_fdopen(file,mode,__LINE__,__FILE__) 130#define fclose(file) curl_fclose(file,__LINE__,__FILE__) 131 132#endif /* MEMDEBUG_NODEFINES */ 133 134#endif /* _CURL_MEMDEBUG_H */ 135#endif /* CURLDEBUG */ 136 137#ifndef fake_sclose 138#define fake_sclose(x) 139#endif 140