/
alloc.c
43 lines (37 loc) · 922 Bytes
/
alloc.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
#include <stdio.h>
#include <stdlib.h>
#include "alloc.h"
/**
Implementation of memory allocation functions
**/
/**
Allocates a block of size*n filled with 0's
@param size size of type
@param n number of blocks of size "size"
@return Allocated poiner
**/
void* callocx(size_t size, size_t n){
void* ptr = calloc(size,n);
if(ptr==NULL){
fprintf(stderr,"%s\n","Could not allocate memory");
perror("Erro");
exit(EXIT_FAILURE);
}
return(ptr);
}
void* reallocx(void* ptr,size_t size){
void *aux = realloc(ptr,size);
if(size==0){
if(aux!=NULL){
fprintf(stderr,"%s\n","Could not allocate memory");
perror("Erro");
exit(EXIT_FAILURE);
}
}
else if(aux==NULL){
fprintf(stderr,"%s\n","Could not allocate memory");
perror("Erro");
exit(EXIT_FAILURE);
}
return(aux);
}