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