-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.c
56 lines (45 loc) · 872 Bytes
/
utils.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
45
46
47
48
49
50
51
52
53
54
55
56
/*
* utils.c
*
* Created on: 31 May 2016
* Author: ajuaristi <[email protected]>
*/
#include <syslog.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include "utils.h"
void fatal(const char *message)
{
// syslog(SYSLOG_FACILITY | LOG_ERR, "FATAL ERROR: %s", message);
// syslog(SYSLOG_FACILITY | LOG_ERR, "Stopping");
fprintf(stderr, "FATAL ERROR: %s\n", message);
fprintf(stderr, "Stopping.\n");
exit(1);
}
void *ec_malloc(size_t size)
{
void *mem = NULL;
if (!size)
goto end;
mem = calloc(1, size);
if (!mem)
fatal("Out of memory");
end:
return mem;
}
void *ec_malloc_fill(size_t size, const char *data)
{
void *mem = ec_malloc(size);
memcpy(mem, data, size);
return mem;
}
void *ec_realloc(void *ptr, size_t size)
{
void *mem = NULL;
if (!ptr)
mem = ec_malloc(size);
else
mem = realloc(mem, size);
return mem;
}