Fixed license declaration at spec file
[platform/upstream/gdbm.git] / src / mem.c
1 /* This file is part of GDBM, the GNU data base manager.
2    Copyright (C) 2011, 2013 Free Software Foundation, Inc.
3
4    GDBM is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 3, or (at your option)
7    any later version.
8
9    GDBM is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with GDBM. If not, see <http://www.gnu.org/licenses/>.   */
16
17 # include "autoconf.h"
18 # include "gdbm.h"
19 # include "gdbmapp.h"
20 # include "gdbmdefs.h"
21
22 void
23 ealloc_die ()
24 {
25   error ("%s", strerror (ENOMEM));
26   exit (EXIT_FATAL);
27 }
28
29 void *
30 emalloc (size_t size)
31 {
32   void *p = malloc (size);
33   if (!p)
34     ealloc_die ();
35   return p;
36 }
37
38 void *
39 erealloc (void *ptr, size_t size)
40 {
41   void *newptr = realloc (ptr, size);
42   if (!newptr)
43     ealloc_die ();
44   return newptr;
45 }
46
47 void *
48 ecalloc (size_t nmemb, size_t size)
49 {
50   void *p = calloc (nmemb, size);
51   if (!p)
52     ealloc_die ();
53   return p;
54 }
55
56 void *
57 ezalloc (size_t size)
58 {
59   return ecalloc (1, size);
60 }
61
62 char *
63 estrdup (const char *str)
64 {
65   char *p;
66
67   if (!str)
68     return NULL;
69   p = emalloc (strlen (str) + 1);
70   strcpy (p, str);
71   return p;
72 }
73
74