-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
44 lines (41 loc) · 882 Bytes
/
utils.c
File metadata and controls
44 lines (41 loc) · 882 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
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <error.h>
#include <errno.h>
#include "utils.h"
/**
* Get memory space and check, wheter I have it
*/
void *
xmalloc(size_t size){
void * pointer;
pointer = malloc(size);
if(pointer == NULL){
error(1, 0, "Could not allocate enough space!");
}
return pointer;
}
/**
* reallocate space and check it
*/
void *
xrealloc(void * pointer, size_t size){
pointer = realloc(pointer, size);
if(pointer == NULL){
error(1, 0, "Could not reallocate space!");
}
return pointer;
}
/**
* safe version of strcat
*/
void
cat(char **to, char * from){
int length = strlen(*to) + strlen(from) + 1;
*to = (char *) xrealloc(*to, length * sizeof(char));
if(strcat(*to, from) != *to){
error(1, 0, "Could not concate the string %s\n", from);
}
}
/* EOF */