Fixed bug#920
[gnupg.git] / jnlib / t-support.c
blob756c54c7fb737385e0fca79a214f6262e851beb1
1 /* t-support.c - helper functions for the regression tests.
2 * Copyright (C) 2007 Free Software Foundation, Inc.
4 * This file is part of JNLIB.
6 * JNLIB is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 3 of
9 * the License, or (at your option) any later version.
11 * JNLIB is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <assert.h>
27 #include "t-support.h"
30 /* Replacements for the malloc functions as used here. */
32 static void
33 out_of_memory (void)
35 fprintf (stderr,"error: out of core in regression tests: %s\n",
36 strerror (errno));
37 exit (2);
41 void *
42 gcry_malloc (size_t n)
44 return malloc (n);
47 void *
48 gcry_xmalloc (size_t n)
50 void *p = malloc (n);
51 if (!p)
52 out_of_memory ();
53 return p;
56 char *
57 gcry_strdup (const char *string)
59 return malloc (strlen (string)+1);
63 void *
64 gcry_realloc (void *a, size_t n)
66 return realloc (a, n);
69 void *
70 gcry_xrealloc (void *a, size_t n)
72 void *p = realloc (a, n);
73 if (!p)
74 out_of_memory ();
75 return p;
80 void *
81 gcry_calloc (size_t n, size_t m)
83 return calloc (n, m);
86 void *
87 gcry_xcalloc (size_t n, size_t m)
89 void *p = calloc (n, m);
90 if (!p)
91 out_of_memory ();
92 return p;
96 char *
97 gcry_xstrdup (const char *string)
99 void *p = malloc (strlen (string)+1);
100 if (!p)
101 out_of_memory ();
102 strcpy (p, string);
103 return p;
106 void
107 gcry_free (void *a)
109 if (a)
110 free (a);
115 /* Stubs for gpg-error functions required because some compilers do
116 not eliminate the supposed-to-be-unused-inline-functions and thus
117 require functions called from these inline fucntions. Although we
118 do not use gpg-error, gpg-error.h may get included via gcrypt.h if
119 it happens to be used used in libjnlib-config.h. */
121 gpg_err_code_from_errno (int err)
123 (void)err;
124 assert (!"stub function");
125 return -1;
129 /* Retrieve the error code directly from the ERRNO variable. This
130 returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
131 (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
133 gpg_err_code_from_syserror (void)
135 assert (!"stub function");
136 return -1;