]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/alloc.c
ebl add sql_escape to catalog messages
[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-2006 Kern Sibbald
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
13    version 2 as amended with additional clauses defined in the
14    file LICENSE in the main source directory.
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 
19    the file LICENSE for additional details.
20
21  */
22
23 #ifdef NEEDED
24
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #ifdef TESTERR
29 #undef NULL
30 #define NULL  buf
31 #endif
32
33 /*LINTLIBRARY*/
34
35 #define V        (void)
36
37 #ifdef SMARTALLOC
38
39 extern void *sm_malloc();
40
41 /*  SM_ALLOC  --  Allocate buffer and signal on error  */
42
43 void *sm_alloc(char *fname, int lineno, unsigned int nbytes)
44 {
45    void *buf;
46
47    if ((buf = sm_malloc(fname, lineno, nbytes)) != NULL) {
48       return buf;
49    }
50    V fprintf(stderr, "\nBoom!!!  Memory capacity exceeded.\n");
51    V fprintf(stderr, "  Requested %u bytes at line %d of %s.\n",
52       nbytes, lineno, fname);
53    abort();
54    /*NOTREACHED*/
55 }
56 #else
57
58 /*  ALLOC  --  Allocate buffer and signal on error  */
59
60 void *alloc(unsigned int nbytes)
61 {
62    void *buf;
63
64    if ((buf = malloc(nbytes)) != NULL) {
65       return buf;
66    }
67    V fprintf(stderr, "\nBoom!!!  Memory capacity exceeded.\n");
68    V fprintf(stderr, "  Requested %u bytes.\n", nbytes);
69    abort();
70    /*NOTREACHED*/
71 }
72 #endif
73 #endif