build: Add QuaggaId to README.NetBSD
[jleu-quagga.git] / lib / memory.h
bloba7eddce4e13e493c04a5d7b73b822721a0fd2707
1 /* Memory management routine
2 Copyright (C) 1998 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
21 #ifndef _ZEBRA_MEMORY_H
22 #define _ZEBRA_MEMORY_H
24 /* For pretty printing of memory allocate information. */
25 struct memory_list
27 int index;
28 const char *format;
31 struct mlist {
32 struct memory_list *list;
33 const char *name;
36 #include "lib/memtypes.h"
38 extern struct mlist mlists[];
40 /* #define MEMORY_LOG */
41 #ifdef MEMORY_LOG
42 #define XMALLOC(mtype, size) \
43 mtype_zmalloc (__FILE__, __LINE__, (mtype), (size))
44 #define XCALLOC(mtype, size) \
45 mtype_zcalloc (__FILE__, __LINE__, (mtype), (size))
46 #define XREALLOC(mtype, ptr, size) \
47 mtype_zrealloc (__FILE__, __LINE__, (mtype), (ptr), (size))
48 #define XFREE(mtype, ptr) \
49 do { \
50 mtype_zfree (__FILE__, __LINE__, (mtype), (ptr)); \
51 ptr = NULL; } \
52 while (0)
53 #define XSTRDUP(mtype, str) \
54 mtype_zstrdup (__FILE__, __LINE__, (mtype), (str))
55 #else
56 #define XMALLOC(mtype, size) zmalloc ((mtype), (size))
57 #define XCALLOC(mtype, size) zcalloc ((mtype), (size))
58 #define XREALLOC(mtype, ptr, size) zrealloc ((mtype), (ptr), (size))
59 #define XFREE(mtype, ptr) do { \
60 zfree ((mtype), (ptr)); \
61 ptr = NULL; } \
62 while (0)
63 #define XSTRDUP(mtype, str) zstrdup ((mtype), (str))
64 #endif /* MEMORY_LOG */
66 /* Prototypes of memory function. */
67 extern void *zmalloc (int type, size_t size);
68 extern void *zcalloc (int type, size_t size);
69 extern void *zrealloc (int type, void *ptr, size_t size);
70 extern void zfree (int type, void *ptr);
71 extern char *zstrdup (int type, const char *str);
73 extern void *mtype_zmalloc (const char *file, int line, int type, size_t size);
75 extern void *mtype_zcalloc (const char *file, int line, int type, size_t size);
77 extern void *mtype_zrealloc (const char *file, int line, int type, void *ptr,
78 size_t size);
80 extern void mtype_zfree (const char *file, int line, int type,
81 void *ptr);
83 extern char *mtype_zstrdup (const char *file, int line, int type,
84 const char *str);
85 extern void memory_init (void);
86 extern void log_memstats_stderr (const char *);
88 /* return number of allocations outstanding for the type */
89 extern unsigned long mtype_stats_alloc (int);
91 /* Human friendly string for given byte count */
92 #define MTYPE_MEMSTR_LEN 20
93 extern const char *mtype_memstr (char *, size_t, unsigned long);
94 #endif /* _ZEBRA_MEMORY_H */