~ubuntu-branches/ubuntu/dapper/gnupg2/dapper

« back to all changes in this revision

Viewing changes to tools/no-libgcrypt.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Mueller
  • Date: 2005-03-29 10:30:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050329103032-sj42n2ain3ipx310
Tags: upstream-1.9.15
ImportĀ upstreamĀ versionĀ 1.9.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* no-libgcrypt.c - Replacement functions for libgcrypt.
 
2
 *      Copyright (C) 2003 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuPG.
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
#include <stdio.h>
 
23
#include <stdlib.h>
 
24
#include <string.h>
 
25
#include <errno.h>
 
26
 
 
27
#include "../common/util.h"
 
28
#include "i18n.h"
 
29
 
 
30
 
 
31
/* Replace libgcrypt's malloc functions which are used by
 
32
   ../jnlib/libjnlib.a .  ../common/util.h defines macros to map them
 
33
   to xmalloc etc. */
 
34
static void
 
35
out_of_core (void)
 
36
{
 
37
  log_fatal (_("error allocating enough memory: %s\n"), strerror (errno));
 
38
}
 
39
 
 
40
 
 
41
void *
 
42
gcry_malloc (size_t n)
 
43
{
 
44
  return malloc (n);
 
45
}
 
46
 
 
47
void *
 
48
gcry_xmalloc (size_t n)
 
49
{
 
50
  void *p = malloc (n);
 
51
  if (!p)
 
52
    out_of_core ();
 
53
  return p;
 
54
}
 
55
 
 
56
 
 
57
void *
 
58
gcry_realloc (void *a, size_t n)
 
59
{
 
60
  return realloc (a, n);
 
61
}
 
62
 
 
63
void *
 
64
gcry_xrealloc (void *a, size_t n)
 
65
{
 
66
  void *p = realloc (a, n);
 
67
  if (!p)
 
68
    out_of_core ();
 
69
  return p;
 
70
}
 
71
 
 
72
 
 
73
 
 
74
void *
 
75
gcry_calloc (size_t n, size_t m)
 
76
{
 
77
  return calloc (n, m);
 
78
}
 
79
 
 
80
void *
 
81
gcry_xcalloc (size_t n, size_t m)
 
82
{
 
83
  void *p = calloc (n, m);
 
84
  if (!p)
 
85
    out_of_core ();
 
86
  return p;
 
87
}
 
88
 
 
89
 
 
90
char *
 
91
gcry_xstrdup (const char *string)
 
92
{
 
93
  void *p = malloc (strlen (string)+1);
 
94
  if (!p)
 
95
    out_of_core ();
 
96
  strcpy( p, string );
 
97
  return p;
 
98
}
 
99
 
 
100
void
 
101
gcry_free (void *a)
 
102
{
 
103
  if (a)
 
104
    free (a);
 
105
}