]> git.notmuchmail.org Git - notmuch/blob - xutil.c
Remove test programs, xapian-dump and notmuch-index-message
[notmuch] / xutil.c
1 /* xutil.c - Various wrapper functions to abort on error.
2  *
3  * Copyright © 2009 Carl Worth
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 #define _GNU_SOURCE /* For strndup */
22 #include "notmuch-private.h"
23
24 #include <stdio.h>
25
26 void *
27 xcalloc (size_t nmemb, size_t size)
28 {
29     void *ret;
30
31     ret = calloc (nmemb, size);
32     if (ret == NULL) {
33         fprintf (stderr, "Out of memory.\n");
34         exit (1);
35     }
36
37     return ret;
38 }
39
40 void *
41 xmalloc (size_t size)
42 {
43     void *ret;
44
45     ret = malloc (size);
46     if (ret == NULL) {
47         fprintf (stderr, "Out of memory.\n");
48         exit (1);
49     }
50
51     return ret;
52 }
53
54 void *
55 xrealloc (void *ptr, size_t size)
56 {
57     void *ret;
58
59     ret = realloc (ptr, size);
60     if (ret == NULL) {
61         fprintf (stderr, "Out of memory.\n");
62         exit (1);
63     }
64
65     return ret;
66 }
67
68 char *
69 xstrdup (const char *s)
70 {
71     char *ret;
72
73     ret = strdup (s);
74     if (ret == NULL) {
75         fprintf (stderr, "Out of memory.\n");
76         exit (1);
77     }
78
79     return ret;
80 }
81
82 char *
83 xstrndup (const char *s, size_t n)
84 {
85     char *ret;
86
87     ret = strndup (s, n);
88     if (ret == NULL) {
89         fprintf (stderr, "Out of memory.\n");
90         exit (1);
91     }
92
93     return ret;
94 }