2 /*****************************************************************************
4 * Project ___| | | | _ \| |
6 * | (__| |_| | _ <| |___
7 * \___|\___/|_| \_\_____|
9 * Copyright (C) 2000, Daniel Stenberg, <daniel@haxx.se>, et al.
11 * In order to be useful for every potential user, curl and libcurl are
12 * dual-licensed under the MPL and the MIT/X-derivate licenses.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the MPL or the MIT/X-derivate
17 * licenses. You may pick one of these licenses.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
23 *****************************************************************************/
27 #include <curl/curl.h>
29 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
31 #else /* some kind of unix */
32 #ifdef HAVE_SYS_SOCKET_H
33 #include <sys/socket.h>
37 #define _MPRINTF_REPLACE
38 #include <curl/mprintf.h>
48 /* DONT include memdebug.h here! */
51 * Note that these debug functions are very simple and they are meant to
52 * remain so. For advanced analysis, record a log file and write perl scripts
55 * Don't use these with multithreaded test programs!
60 /* this sets the log file name */
61 void curl_memdebug(const char *logname)
64 logfile = fopen(logname, "w");
70 void *curl_domalloc(size_t size, int line, const char *source)
72 void *mem=(malloc)(size);
74 fprintf(logfile, "MEM %s:%d malloc(%d) = %p\n",
75 source, line, size, mem);
79 char *curl_dostrdup(const char *str, int line, const char *source)
85 fprintf(stderr, "ILLEGAL strdup() on NULL at %s:%d\n",
93 fprintf(logfile, "MEM %s:%d strdup(%p) (%d) = %p\n",
94 source, line, str, len, mem);
98 void *curl_dorealloc(void *ptr, size_t size, int line, const char *source)
100 void *mem=(realloc)(ptr, size);
102 fprintf(logfile, "MEM %s:%d realloc(%p, %d) = %p\n",
103 source, line, ptr, size, mem);
107 void curl_dofree(void *ptr, int line, const char *source)
110 fprintf(stderr, "ILLEGAL free() on NULL at %s:%d\n",
118 fprintf(logfile, "MEM %s:%d free(%p)\n", source, line, ptr);
121 int curl_socket(int domain, int type, int protocol, int line, char *source)
123 int sockfd=(socket)(domain, type, protocol);
125 fprintf(logfile, "FD %s:%d socket() = %d\n",
126 source, line, sockfd);
130 int curl_accept(int s, struct sockaddr *addr, socklen_t *addrlen,
131 int line, const char *source)
133 int sockfd=(accept)(s, addr, addrlen);
135 fprintf(logfile, "FD %s:%d accept() = %d\n",
136 source, line, sockfd);
140 /* this is our own defined way to close sockets on *ALL* platforms */
141 int curl_sclose(int sockfd, int line, char *source)
143 int res=sclose(sockfd);
145 fprintf(logfile, "FD %s:%d sclose(%d)\n",
146 source, line, sockfd);
150 FILE *curl_fopen(const char *file, const char *mode,
151 int line, const char *source)
153 FILE *res=(fopen)(file, mode);
155 fprintf(logfile, "FILE %s:%d fopen(\"%s\") = %p\n",
156 source, line, file, res);
160 int curl_fclose(FILE *file, int line, const char *source)
162 int res=(fclose)(file);
164 fprintf(logfile, "FILE %s:%d fclose(%p)\n",
169 #endif /* MALLOCDEBUG */
173 * eval: (load-file "../curl-mode.el")
176 * vim: et sw=2 ts=2 sts=2 tw=78