2
0

memdebug.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 - 2004, 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$
  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. #include "setup.h"
  31. #ifdef HAVE_SYS_TYPES_H
  32. #include <sys/types.h>
  33. #endif
  34. #ifdef HAVE_SYS_SOCKET_H
  35. #include <sys/socket.h>
  36. #endif
  37. #include <stdio.h>
  38. #ifdef HAVE_MEMORY_H
  39. #include <memory.h>
  40. #endif
  41. #define logfile curl_debuglogfile
  42. extern FILE *logfile;
  43. /* memory functions */
  44. void *curl_domalloc(size_t size, int line, const char *source);
  45. void *curl_docalloc(size_t elements, size_t size, int line, const char *source);
  46. void *curl_dorealloc(void *ptr, size_t size, int line, const char *source);
  47. void curl_dofree(void *ptr, int line, const char *source);
  48. char *curl_dostrdup(const char *str, int line, const char *source);
  49. void curl_memdebug(const char *logname);
  50. void curl_memlimit(long limit);
  51. /* file descriptor manipulators */
  52. int curl_socket(int domain, int type, int protocol, int line , const char *);
  53. int curl_sclose(int sockfd, int, const char *source);
  54. int curl_accept(int s, void *addr, void *addrlen,
  55. int line, const char *source);
  56. /* FILE functions */
  57. FILE *curl_fopen(const char *file, const char *mode, int line,
  58. const char *source);
  59. int curl_fclose(FILE *file, int line, const char *source);
  60. #ifndef MEMDEBUG_NODEFINES
  61. /* Set this symbol on the command-line, recompile all lib-sources */
  62. #undef strdup
  63. #define strdup(ptr) curl_dostrdup(ptr, __LINE__, __FILE__)
  64. #define malloc(size) curl_domalloc(size, __LINE__, __FILE__)
  65. #define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
  66. #define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
  67. #define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
  68. #define socket(domain,type,protocol)\
  69. curl_socket(domain,type,protocol,__LINE__,__FILE__)
  70. #undef accept /* for those with accept as a macro */
  71. #define accept(sock,addr,len)\
  72. curl_accept(sock,addr,len,__LINE__,__FILE__)
  73. #define getaddrinfo(host,serv,hint,res) \
  74. curl_getaddrinfo(host,serv,hint,res,__LINE__,__FILE__)
  75. #define freeaddrinfo(data) \
  76. curl_freeaddrinfo(data,__LINE__,__FILE__)
  77. /* sclose is probably already defined, redefine it! */
  78. #undef sclose
  79. #define sclose(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
  80. /* ares-adjusted define: */
  81. #undef closesocket
  82. #define closesocket(sockfd) curl_sclose(sockfd,__LINE__,__FILE__)
  83. #undef fopen
  84. #define fopen(file,mode) curl_fopen(file,mode,__LINE__,__FILE__)
  85. #define fclose(file) curl_fclose(file,__LINE__,__FILE__)
  86. #endif /* MEMDEBUG_NODEFINES */
  87. #endif /* _CURL_MEDEBUG_H */
  88. #endif /* CURLDEBUG */