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