Fixed EOF detection for encrypted packets.
[gnupg.git] / jnlib / t-support.c
blobd8eba3b590cf2995956d6100bdbcfd234a9d9c73
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 char *p = malloc (strlen (string)+1);
60 if (p)
61 strcpy (p, string);
62 return p;
66 void *
67 gcry_realloc (void *a, size_t n)
69 return realloc (a, n);
72 void *
73 gcry_xrealloc (void *a, size_t n)
75 void *p = realloc (a, n);
76 if (!p)
77 out_of_memory ();
78 return p;
83 void *
84 gcry_calloc (size_t n, size_t m)
86 return calloc (n, m);
89 void *
90 gcry_xcalloc (size_t n, size_t m)
92 void *p = calloc (n, m);
93 if (!p)
94 out_of_memory ();
95 return p;
99 char *
100 gcry_xstrdup (const char *string)
102 void *p = malloc (strlen (string)+1);
103 if (!p)
104 out_of_memory ();
105 strcpy (p, string);
106 return p;
109 void
110 gcry_free (void *a)
112 if (a)
113 free (a);
118 /* Stubs for gpg-error functions required because some compilers do
119 not eliminate the supposed-to-be-unused-inline-functions and thus
120 require functions called from these inline fucntions. Although we
121 do not use gpg-error, gpg-error.h may get included via gcrypt.h if
122 it happens to be used used in libjnlib-config.h. */
124 gpg_err_code_from_errno (int err)
126 (void)err;
127 assert (!"stub function");
128 return -1;
132 /* Retrieve the error code directly from the ERRNO variable. This
133 returns GPG_ERR_UNKNOWN_ERRNO if the system error is not mapped
134 (report this) and GPG_ERR_MISSING_ERRNO if ERRNO has the value 0. */
136 gpg_err_code_from_syserror (void)
138 assert (!"stub function");
139 return -1;