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