2008-02-01 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / tools / no-libgcrypt.c
blob009fd95a5924fd6d3fde75181eba3aa6ed5778a2
1 /* no-libgcrypt.c - Replacement functions for libgcrypt.
2 * Copyright (C) 2003 Free Software Foundation, Inc.
4 * This file is free software; as a special exception the author gives
5 * unlimited permission to copy and/or distribute it, with or without
6 * modifications, as long as this notice is preserved.
7 *
8 * This file is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY, to the extent permitted by law; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 * PURPOSE.
14 #include <config.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <errno.h>
20 #include "../common/util.h"
21 #include "i18n.h"
24 /* Replace libgcrypt's malloc functions which are used by
25 ../jnlib/libjnlib.a . ../common/util.h defines macros to map them
26 to xmalloc etc. */
27 static void
28 out_of_memory (void)
30 log_fatal (_("error allocating enough memory: %s\n"), strerror (errno));
34 void *
35 gcry_malloc (size_t n)
37 return malloc (n);
40 void *
41 gcry_malloc_secure (size_t n)
43 return malloc (n);
46 void *
47 gcry_xmalloc (size_t n)
49 void *p = malloc (n);
50 if (!p)
51 out_of_memory ();
52 return p;
55 char *
56 gcry_strdup (const char *string)
58 return malloc (strlen (string)+1);
62 void *
63 gcry_realloc (void *a, size_t n)
65 return realloc (a, n);
68 void *
69 gcry_xrealloc (void *a, size_t n)
71 void *p = realloc (a, n);
72 if (!p)
73 out_of_memory ();
74 return p;
79 void *
80 gcry_calloc (size_t n, size_t m)
82 return calloc (n, m);
85 void *
86 gcry_xcalloc (size_t n, size_t m)
88 void *p = calloc (n, m);
89 if (!p)
90 out_of_memory ();
91 return p;
95 char *
96 gcry_xstrdup (const char *string)
98 void *p = malloc (strlen (string)+1);
99 if (!p)
100 out_of_memory ();
101 strcpy( p, string );
102 return p;
105 void
106 gcry_free (void *a)
108 if (a)
109 free (a);
113 /* We need this dummy because exechelp.c uses gcry_control to
114 terminate the secure memeory. */
115 gcry_error_t
116 gcry_control (enum gcry_ctl_cmds CMD, ...)
118 return 0;
121 void
122 gcry_set_outofcore_handler (gcry_handler_no_mem_t h, void *opaque)
124 (void)h;
125 (void)opaque;
128 void
129 gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque)
131 (void)fnc;
132 (void)opaque;
135 void
136 gcry_set_log_handler (gcry_handler_log_t f, void *opaque)
138 (void)f;
139 (void)opaque;