Line data Source code
1 : /* keybox-util.c - Utility functions for Keybox
2 : * Copyright (C) 2001 Free Software Foundation, Inc.
3 : *
4 : * This file is part of GnuPG.
5 : *
6 : * GnuPG is free software; you can redistribute it and/or modify
7 : * it under the terms of the GNU General Public License as published by
8 : * the Free Software Foundation; either version 3 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * GnuPG is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public License
17 : * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 : */
19 :
20 : #include <config.h>
21 : #include <stdlib.h>
22 : #include <stdio.h>
23 : #include <string.h>
24 :
25 : #include "keybox-defs.h"
26 :
27 :
28 : static void *(*alloc_func)(size_t n) = malloc;
29 : static void *(*realloc_func)(void *p, size_t n) = realloc;
30 : static void (*free_func)(void*) = free;
31 :
32 :
33 :
34 : void
35 3 : keybox_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
36 : void *(*new_realloc_func)(void *p, size_t n),
37 : void (*new_free_func)(void*) )
38 : {
39 3 : alloc_func = new_alloc_func;
40 3 : realloc_func = new_realloc_func;
41 3 : free_func = new_free_func;
42 3 : }
43 :
44 : void *
45 175453 : _keybox_malloc (size_t n)
46 : {
47 175453 : return alloc_func (n);
48 : }
49 :
50 : void *
51 44 : _keybox_realloc (void *a, size_t n)
52 : {
53 44 : return realloc_func (a, n);
54 : }
55 :
56 : void *
57 87766 : _keybox_calloc (size_t n, size_t m)
58 : {
59 87766 : void *p = _keybox_malloc (n*m);
60 87766 : if (p)
61 87766 : memset (p, 0, n* m);
62 87766 : return p;
63 : }
64 :
65 : void
66 510588 : _keybox_free (void *p)
67 : {
68 510588 : if (p)
69 170470 : free_func (p);
70 510588 : }
|