]> git.cworth.org Git - fips/blob - xmalloc.c
Add explicit link to libpthread, to work around debugging issues
[fips] / xmalloc.c
1 /* Copyright © 2013, Intel Corporation
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "xmalloc.h"
27
28 void *
29 xmalloc (size_t size)
30 {
31         void *ret;
32
33         ret = malloc (size);
34         if (size != 0 && ret == NULL) {
35                 fprintf (stderr, "Out of memory\n");
36                 exit (1);
37         }
38
39         return ret;
40 }
41
42 void *
43 xcalloc (size_t nmemb, size_t size)
44 {
45         void *ret;
46
47         ret = calloc (nmemb, size);
48         if (size != 0 && ret == NULL) {
49                 fprintf (stderr, "Out of memory\n");
50                 exit (1);
51         }
52
53         return ret;
54 }
55
56 void *
57 xrealloc (void *ptr, size_t size)
58 {
59         void *ret;
60
61         ret = realloc (ptr, size);
62         if (size != 0 && ret == NULL) {
63                 fprintf (stderr, "Out of memory\n");
64                 exit (1);
65         }
66
67         return ret;
68 }
69
70 char *
71 xstrdup (const char *s)
72 {
73         void *ret;
74
75         if (s == NULL)
76                 return NULL;
77
78         ret = strdup (s);
79
80         if (ret == NULL) {
81                 fprintf (stderr, "Out of memory\n");
82                 exit (1);
83         }
84
85         return ret;
86 }
87