"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "wml_backend/p2_mp4h/lib/xmalloc.c" between
wml-2.28.0.tar.xz and wml-2.30.0.tar.xz

About: WML (Website META Language) is an extensible Webdesigner’s off-line HTML generation toolkit.

xmalloc.c  (wml-2.28.0.tar.xz):xmalloc.c  (wml-2.30.0.tar.xz)
skipping to change at line 46 skipping to change at line 46
#ifndef EXIT_FAILURE #ifndef EXIT_FAILURE
# define EXIT_FAILURE 1 # define EXIT_FAILURE 1
#endif #endif
/* Prototypes for functions defined here. */ /* Prototypes for functions defined here. */
#if defined (__STDC__) && __STDC__ #if defined (__STDC__) && __STDC__
static void *fixup_null_alloc (size_t n); static void *fixup_null_alloc (size_t n);
void *xmalloc (size_t n); void *xmalloc (size_t n);
void *xcalloc (size_t n, size_t s); void *xcalloc (size_t n, size_t s);
void *xrealloc (void *p, size_t n); void *xrealloc (void *p, size_t n);
void xfree (void *p);
#endif #endif
/* Exit value when the requested amount of memory is not available. /* Exit value when the requested amount of memory is not available.
The caller may set it to some other value. */ The caller may set it to some other value. */
int xmalloc_exit_failure = EXIT_FAILURE; int xmalloc_exit_failure = EXIT_FAILURE;
void error (int, int, const char *, ...); void error (int, int, const char *, ...);
static void * static void * fixup_null_alloc (const size_t n)
fixup_null_alloc (n)
size_t n;
{ {
void *p; void *p = NULL;
p = 0;
if (n == 0) if (n == 0)
p = malloc ((size_t) 1); p = malloc ((size_t) 1);
if (p == 0) if (!p)
error (xmalloc_exit_failure, 0, _("Memory exhausted")); error (xmalloc_exit_failure, 0, _("Memory exhausted"));
return p; return p;
} }
/* Allocate N bytes of memory dynamically, with error checking. */ /* Allocate N bytes of memory dynamically, with error checking. */
void * void * xmalloc (const size_t n)
xmalloc (n)
size_t n;
{ {
void *p; void *p = malloc (n);
if (!p)
p = malloc (n);
if (p == 0)
p = fixup_null_alloc (n); p = fixup_null_alloc (n);
return p; return p;
} }
/* Allocate memory for N elements of S bytes, with error checking. */ /* Allocate memory for N elements of S bytes, with error checking. */
void * void * xcalloc (size_t n, size_t s)
xcalloc (n, s)
size_t n, s;
{ {
void *p; void *p = calloc (n, s);
if (!p)
p = calloc (n, s);
if (p == 0)
p = fixup_null_alloc (n); p = fixup_null_alloc (n);
return p; return p;
} }
/* Change the size of an allocated block of memory P to N bytes, /* Change the size of an allocated block of memory P to N bytes,
with error checking. with error checking.
If P is NULL, run xmalloc. */ If P is NULL, run xmalloc. */
void * void * xrealloc (void *p, size_t n)
xrealloc (p, n)
void *p;
size_t n;
{ {
if (p == 0) if (!p)
return xmalloc (n); return xmalloc (n);
p = realloc (p, n); p = realloc (p, n);
if (p == 0) if (!p)
p = fixup_null_alloc (n); p = fixup_null_alloc (n);
return p; return p;
} }
void
xfree (p)
void *p;
{
if (p != 0)
free(p);
p = 0;
}
 End of changes. 12 change blocks. 
28 lines changed or deleted 12 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)