blob: 2aea3b92efd0080a0ead1c74c58874fb55320b1c (
plain)
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
|
#include <stdlib.h>
#include <stdio.h>
/***********************************************************************
*
* Procedure:
* safemalloc - mallocs specified space or exits if there's a
* 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;
}
|