2023-08-28 05:57:34 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Procedure:
|
2024-10-06 22:00:57 +00:00
|
|
|
* safemalloc - mallocs specified space or exits if there's a
|
2023-08-28 05:57:34 +00:00
|
|
|
* problem
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
char *safemalloc(int length)
|
|
|
|
{
|
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
if(length <= 0)
|
|
|
|
length = 1;
|
|
|
|
|
|
|
|
ptr = malloc(length);
|
|
|
|
if(ptr == (char *)0)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"malloc of %d bytes failed. Exiting\n",length);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|