-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory.c
44 lines (38 loc) · 855 Bytes
/
memory.c
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
/*
* memory.c
* Developed by Haroldo Gambini Santos
* hsantos@ic.uff.br
*/
#include <stdio.h>
#include <stdlib.h>
#include "memory.h"
void *xmalloc( const size_t size )
{
void *result = malloc( size );
if (!result)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
exit(1);
}
return result;
}
void *xcalloc( const size_t elements, const size_t size )
{
void *result = calloc( elements, size );
if (!result)
{
fprintf(stderr, "No more memory available. Trying to callocte %zu bytes.", size);
exit(1);
}
return result;
}
void *xrealloc( void *ptr, const size_t size )
{
void *result = realloc( ptr, size );
if (!result)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
exit(1);
}
return result;
}