YetAnotherCoupler 3.5.2
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#ifndef YAC_CODE_COVERAGE_TEST
55#define TEST_POINTER(SIZE) \
56 if (p || !(SIZE)) \
57 ; \
58 else \
59 symprefix(abort_message)(strerror(errno), source, line);
60#else
61#define TEST_POINTER(SIZE)
62#endif
63
64void *
65symprefix(xcalloc)(size_t nmemb, size_t size, const char *source, int line)
66{
67 void *p = calloc(nmemb, size);
68 TEST_POINTER(nmemb && size)
69 return p;
70}
71
72
73void *
74symprefix(xmalloc)(size_t size, const char *source, int line)
75{
76 void *p = malloc(size);
77 TEST_POINTER(size)
78 return p;
79}
80
81
82void *
83symprefix(xrealloc)(void *ptr, size_t size, const char *source, int line)
84{
85 void *p;
86 if (size != 0) {
87 p = realloc(ptr, size);
88 TEST_POINTER(size)
89 } else {
90 free(ptr);
91 p = NULL;
92 }
93 return p;
94}
95
96/*
97 * Local Variables:
98 * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
99 * license-markup: "doxygen"
100 * license-default: "bsd"
101 * End:
102 */
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:57
#define TEST_POINTER(SIZE)
Definition xmalloc.c:55