2005-04-15 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / kbx / keybox-util.c
blobed5d93de006c1ead58d69fa246c5e7b6862dc1b6
1 /* keybox-util.c - Utility functions for Keybox
2 * Copyright (C) 2001 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
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 2 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include <config.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "keybox-defs.h"
29 static void *(*alloc_func)(size_t n) = malloc;
30 static void *(*realloc_func)(void *p, size_t n) = realloc;
31 static void (*free_func)(void*) = free;
35 void
36 keybox_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
37 void *(*new_realloc_func)(void *p, size_t n),
38 void (*new_free_func)(void*) )
40 alloc_func = new_alloc_func;
41 realloc_func = new_realloc_func;
42 free_func = new_free_func;
45 void *
46 _keybox_malloc (size_t n)
48 return alloc_func (n);
51 void *
52 _keybox_realloc (void *a, size_t n)
54 return realloc_func (a, n);
57 void *
58 _keybox_calloc (size_t n, size_t m)
60 void *p = _keybox_malloc (n*m);
61 if (p)
62 memset (p, 0, n* m);
63 return p;
66 void
67 _keybox_free (void *p)
69 if (p)
70 free_func (p);