1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/* Wrappers for standard storage allocation functions. The tests for zero
size, etc., are necessitated by the way in which the original X11
scan-conversion code was written. */
#include "sys-defines.h"
#include "extern.h"
#include "xmi.h"
#include "mi_spans.h"
#include "mi_api.h"
/* wrapper for malloc() */
voidptr_t
#ifdef _HAVE_PROTOS
mi_xmalloc (size_t size)
#else
mi_xmalloc (size)
size_t size;
#endif
{
voidptr_t p;
if (size == 0)
return (voidptr_t)NULL;
p = (voidptr_t) malloc (size);
if (p == (voidptr_t)NULL)
{
fprintf (stderr, "libxmi: ");
perror ("out of memory");
exit (EXIT_FAILURE);
}
return p;
}
/* wrapper for calloc() */
voidptr_t
#ifdef _HAVE_PROTOS
mi_xcalloc (size_t nmemb, size_t size)
#else
mi_xcalloc (nmemb, size)
size_t nmemb, size;
#endif
{
voidptr_t p;
if (size == 0)
return (voidptr_t)NULL;
p = (voidptr_t) calloc (nmemb, size);
if (p == (voidptr_t)NULL)
{
fprintf (stderr, "libxmi: ");
perror ("out of memory");
exit (EXIT_FAILURE);
}
return p;
}
/* wrapper for realloc() */
voidptr_t
#ifdef _HAVE_PROTOS
mi_xrealloc (voidptr_t p, size_t size)
#else
mi_xrealloc (p, size)
voidptr_t p;
size_t size;
#endif
{
if (!p)
return mi_xmalloc (size);
else
{
if (size == 0)
{
free (p);
return (voidptr_t)NULL;
}
p = (voidptr_t) realloc (p, size);
if (p == (voidptr_t)NULL)
{
fprintf (stderr, "libxmi: ");
perror ("out of memory");
exit (EXIT_FAILURE);
}
return p;
}
}
|