2008-05-15 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / keyserver / no-libgcrypt.c
blob2cce156a7f6484c4d52eb27dfc880219cf7f5fc0
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 the
10 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 #include <config.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <errno.h>
19 #include "../common/util.h"
20 #include "i18n.h"
23 /* Replace libgcrypt's malloc functions which are used by
24 ../jnlib/libjnlib.a . ../common/util.h defines macros to map them
25 to xmalloc etc. */
26 static void
27 out_of_memory (void)
29 fprintf (stderr, "error allocating enough memory: %s\n", strerror (errno));
30 exit (2);
34 void *
35 gcry_malloc (size_t n)
37 return malloc (n);
40 void *
41 gcry_xmalloc (size_t n)
43 void *p = malloc (n);
44 if (!p)
45 out_of_memory ();
46 return p;
49 char *
50 gcry_strdup (const char *string)
52 char *p = malloc (strlen (string)+1);
53 if (p)
54 strcpy (p, string);
55 return p;
59 void *
60 gcry_realloc (void *a, size_t n)
62 return realloc (a, n);
65 void *
66 gcry_xrealloc (void *a, size_t n)
68 void *p = realloc (a, n);
69 if (!p)
70 out_of_memory ();
71 return p;
76 void *
77 gcry_calloc (size_t n, size_t m)
79 return calloc (n, m);
82 void *
83 gcry_xcalloc (size_t n, size_t m)
85 void *p = calloc (n, m);
86 if (!p)
87 out_of_memory ();
88 return p;
92 char *
93 gcry_xstrdup (const char *string)
95 void *p = malloc (strlen (string)+1);
96 if (!p)
97 out_of_memory ();
98 strcpy( p, string );
99 return p;
102 void
103 gcry_free (void *a)
105 if (a)
106 free (a);