1
/* xmalloc.c -- malloc with out of memory checking
2
Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 99 Free Software Foundation, Inc.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2, or (at your option)
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software Foundation,
16
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
// TODO better use #define in header file?!
26
void *xmalloc (size_t n) {return malloc(n);}
27
void *xcalloc (size_t n, size_t s) {return calloc(n,s);}
28
void *xrealloc (void *p, size_t n) {return realloc(p,n);}
29
char *xstrdup (const char *p) {return strdup(p);}
31
#else // LGPL LICENSED CODE
38
#include <stdio.h> /* for stderr */
42
#include <sys/types.h>
43
#include <string.h> /* for strlen etc. */
46
#else /* !STDC_HEADERS */
48
extern size_t strlen ();
49
extern char *strcpy ();
59
# define _(Text) gettext (Text)
61
# define textdomain(Domain)
65
/* Prototypes for functions defined here. */
66
#if defined (__STDC__) && __STDC__
67
static VOID *fixup_null_alloc (size_t n);
68
VOID *xmalloc (size_t n);
69
VOID *xcalloc (size_t n, size_t s);
70
VOID *xrealloc (VOID *p, size_t n);
71
char *xstrdup (const char *p);
83
p = malloc ((size_t) 1);
86
/* possible revisions: release some memory and re-try, print
87
more information (e.g. line number of input file) */
88
fprintf(stderr, _("liboauth: Memory exhausted"));
94
/* Allocate N bytes of memory dynamically, with error checking. */
104
p = fixup_null_alloc (n);
108
/* Allocate memory for N elements of S bytes, with error checking. */
118
p = fixup_null_alloc (n);
122
/* Change the size of an allocated block of memory P to N bytes,
124
If P is NULL, run xmalloc. */
135
p = fixup_null_alloc (n);
139
/* Make a copy of a string in a newly allocated block of memory. */
147
p = xmalloc (strlen (str) + 1);