-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathalloc_wrap.c
More file actions
35 lines (32 loc) · 790 Bytes
/
alloc_wrap.c
File metadata and controls
35 lines (32 loc) · 790 Bytes
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
/**
* Wrapping for memory allocation functions
* to exit on a failure with corresponding message.
*
* @authors: Denis Chernikov, Vladislav Kuleykin
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "alloc_wrap.h"
void *my_malloc(size_t size, char *description)
{
void *res = malloc(size);
if (!res)
{
fprintf(stderr, "FATAL ERROR!\n"
"Memory for %s cannot be allocated!\n", description);
exit(-1);
}
return res;
}
void *my_realloc(void *memory, size_t size, char *description)
{
void *res = realloc(memory, size);
if (!res)
{
fprintf(stderr, "FATAL ERROR!\n"
"Memory for %s cannot be reallocated!\n", description);
exit(-1);
}
return res;
}