YetAnotherCoupler 3.2.0_a
Loading...
Searching...
No Matches
xmalloc.c
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Thomas Jahns <jahns@dkrz.de>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
14/*
15 * Maintainer: Thomas Jahns <jahns@dkrz.de>
16 * URL: https://www.dkrz.de/redmine/projects/scales-ppm
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met:
21 *
22 * Redistributions of source code must retain the above copyright notice,
23 * this list of conditions and the following disclaimer.
24 *
25 * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * Neither the name of the DKRZ GmbH nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
34 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
36 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
37 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45#include <errno.h>
46#include <stdlib.h>
47#include <string.h>
48
49#include "ppm/ppm_xfuncs.h"
50#include "ppm/core.h"
51
52#include "ppm/symprefix.h"
53
54#define TEST_POINTER(SIZE) \
55 if (p || !(SIZE)) \
56 ; \
57 else \
58 symprefix(abort_message)(strerror(errno), source, line);
59
60void *
61symprefix(xcalloc)(size_t nmemb, size_t size, const char *source, int line)
62{
63 void *p = calloc(nmemb, size);
64 TEST_POINTER(nmemb && size)
65 return p;
66}
67
68
69void *
70symprefix(xmalloc)(size_t size, const char *source, int line)
71{
72 void *p = malloc(size);
73 TEST_POINTER(size)
74 return p;
75}
76
77
78void *
79symprefix(xrealloc)(void *ptr, size_t size, const char *source, int line)
80{
81 void *p = realloc(ptr, size);
82 TEST_POINTER(size)
83 return p;
84}
85
86/*
87 * Local Variables:
88 * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
89 * license-markup: "doxygen"
90 * license-default: "bsd"
91 * End:
92 */
add versions of standard API functions not returning on error
#define xrealloc(ptr, size)
Definition ppm_xfuncs.h:67
#define xcalloc(nmemb, size)
Definition ppm_xfuncs.h:64
#define xmalloc(size)
Definition ppm_xfuncs.h:66
Define library-specific symbol prefix macros.
#define symprefix(symbol)
Definition symprefix.h:55
#define TEST_POINTER(SIZE)
Definition xmalloc.c:54