1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2010 Index Data.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * \brief Header for memory handling functions.
32 * This is a set of wrapper functions for the memory allocation routines
33 * from stdlib.h.. Such as malloc, free, realloc etc.
34 * These functions calls exit if memory allocation fails.
42 #include <yaz/yconfig.h>
46 /** \brief utility macro which calls xrealloc_f */
47 #define xrealloc(o, x) xrealloc_f(o, x, __FILE__, __LINE__)
48 /** \brief utility macro which calls malloc_f */
49 #define xmalloc(x) xmalloc_f(x, __FILE__, __LINE__)
50 /** \brief utility macro which calls xcalloc_f */
51 #define xcalloc(x,y) xcalloc_f(x,y, __FILE__, __LINE__)
52 /** \brief utility macro which calls xfree_f */
53 #define xfree(x) xfree_f(x, __FILE__, __LINE__)
54 /** \brief utility macro which calls xstrdup_f */
55 #define xstrdup(s) xstrdup_f(s, __FILE__, __LINE__)
56 /** \brief utility macro which calls xstrndup_f */
57 #define xstrndup(s, n) xstrndup_f(s, n, __FILE__, __LINE__)
58 /** \brief utility macro which calls malloc_trav_f */
59 #define xmalloc_trav(s) xmalloc_trav_f(s, __FILE__, __LINE__)
62 \param o buffer to be reallocated
63 \param size size of buffer to be allocated
64 \param file fname location of use
65 \param line line location of use
68 This function is invoked via macro xrealloc in which file and line are set
72 YAZ_EXPORT void *xrealloc_f(void *o, size_t size, const char *file, int line);
74 \param size size of buffer to be allocated
75 \param file fname location of use
76 \param line line location of use
79 This function is invoked via macro xmalloc in which file and line are set
82 YAZ_EXPORT void *xmalloc_f(size_t size, const char *file, int line);
85 \param nmemb number of members
86 \param size size of member
87 \param file fname location of use
88 \param line line location of use
91 This function is invoked via macro xcalloc in which file and line are set
94 YAZ_EXPORT void *xcalloc_f(size_t nmemb, size_t size,
95 const char *file, int line);
97 \param p string to be cloned
98 \param file fname location of use
99 \param line line location of use
100 \returns resulting string
102 This function is invoked via macro xstrdup in which file and line are set
105 YAZ_EXPORT char *xstrdup_f(const char *p, const char *file, int line);
108 \param p string to be cloned
109 \param n max size of resulting string (excluding 0)
110 \param file fname location of use
111 \param line line location of use
112 \returns resulting string
114 This function is invoked via macro xstrndup in which file and line are set
117 YAZ_EXPORT char *xstrndup_f(const char *p, size_t n,
118 const char *file, int line);
121 \param p string to be freed (might be NULL)
122 \param file fname location of use
123 \param line line location of use
125 This function is invoked via macro xfree in which file and line are set
128 YAZ_EXPORT void xfree_f(void *p, const char *file, int line);
130 /** \brief logs all xmalloc buffers
132 \param file fname location of use
133 \param line line location of use
135 This function is invoked via macro xmalloc_trav in which file and line
136 are set automatically. Only if TRACE_XMALLOC > 1 this function
139 YAZ_EXPORT void xmalloc_trav_f(const char *s, const char *file, int line);
147 * c-file-style: "Stroustrup"
148 * indent-tabs-mode: nil
150 * vim: shiftwidth=4 tabstop=8 expandtab