1 /*	$Id: malloc.h 20800 2012-01-19 05:13:45Z m-oki $	*/
2 
3 /*
4  * Copyright (c) 2012, Internet Initiative Japan, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef ARMS_DEBUG
31 
32 #include <stdlib.h>
33 
34 #define MALLOC(size)     malloc(size)
35 #define CALLOC(num,size) calloc((num),(size))
36 #define REALLOC(p,size)  realloc((p),(size))
37 #define FREE(p)          free(p)
38 #define STRDUP(s)        strdup(s)
39 #define MCHECK(p)        /* do nothing */
40 #define FREEALL()	 /* do nothing */
41 #define MSETPOS(p)	 /* do nothing */
42 
43 #else /* ARMS_DEBUG */
44 
45 void arms_malloc_init(void);
46 
47 void *arms_malloc(size_t, const char *, int, const char *);
48 void *arms_calloc(size_t, size_t, const char *, int, const char *);
49 void *arms_realloc(void *, size_t, const char *, int, const char *);
50 void arms_free(void *, const char *, int, const char *);
51 char *arms_strdup(const char *, const char *, int, const char *);
52 void arms_mcheck(void *, const char *, int, const char *);
53 void arms_freeall(void);
54 void arms_msetpos(void *, const char *, int, const char *);
55 
56 #define MALLOC(size)     arms_malloc(size, __FILE__, __LINE__, __func__)
57 #define CALLOC(num,size) arms_calloc((num),(size), __FILE__, __LINE__, __func__)
58 #define REALLOC(p,size)  arms_realloc((p),(size), __FILE__, __LINE__, __func__)
59 #define FREE(p)          arms_free((void *)(p), __FILE__, __LINE__, __func__)
60 #define STRDUP(s)        arms_strdup(s, __FILE__, __LINE__, __func__)
61 #define MCHECK(p)        arms_mcheck(p, __FILE__, __LINE__, __func__)
62 #define FREEALL()	 arms_freeall()
63 #define MSETPOS(p)       arms_msetpos(p, __FILE__, __LINE__, __func__)
64 #endif
65