]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/alloc.c
First cut AutoPrune
[bacula/bacula] / bacula / src / lib / alloc.c
1 /*
2
3         Error checking memory allocator
4
5      Version $Id$
6 */
7
8 /*
9    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License as
13    published by the Free Software Foundation; either version 2 of
14    the License, or (at your option) any later version.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19    General Public License for more details.
20
21    You should have received a copy of the GNU General Public
22    License along with this program; if not, write to the Free
23    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24    MA 02111-1307, USA.
25
26  */
27
28 #ifdef NEEDED
29
30 #include <stdio.h>
31 #include <stdlib.h>
32
33 #ifdef TESTERR
34 #undef NULL
35 #define NULL  buf
36 #endif
37
38 /*LINTLIBRARY*/
39
40 #define V        (void)
41
42 #ifdef SMARTALLOC
43
44 extern void *sm_malloc();
45
46 /*  SM_ALLOC  --  Allocate buffer and signal on error  */
47
48 void *sm_alloc(char *fname, int lineno, unsigned int nbytes)
49 {
50         void *buf;
51
52         if ((buf = sm_malloc(fname, lineno, nbytes)) != NULL) {
53            return buf;
54         }
55         V fprintf(stderr, "\nBoom!!!  Memory capacity exceeded.\n");
56         V fprintf(stderr, "  Requested %u bytes at line %d of %s.\n",
57            nbytes, lineno, fname);
58         abort();
59         /*NOTREACHED*/
60 }
61 #else
62
63 /*  ALLOC  --  Allocate buffer and signal on error  */
64
65 void *alloc(unsigned int nbytes)
66 {
67         void *buf;
68
69         if ((buf = malloc(nbytes)) != NULL) {
70            return buf;
71         }
72         V fprintf(stderr, "\nBoom!!!  Memory capacity exceeded.\n");
73         V fprintf(stderr, "  Requested %u bytes.\n", nbytes);
74         abort();
75         /*NOTREACHED*/
76 }
77 #endif
78 #endif