-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathint_alloc.c
executable file
·56 lines (44 loc) · 1.34 KB
/
int_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
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Written by James Mc Donald 2006
[Antispam: email in reverse] ei.yawlagiun.ti@semaj
int memory allocation functions
Copyright (C) 2006 James Mc Donald,
Computational Astrophysics Laboratory,
National University of Ireland, Galway
This code is covered by the GNU General Public License */
#include "int_alloc.h"
void int_malloc(int **p2p,size_t order){
*p2p=(int*)malloc(sizeof(int)*order);
if(*p2p==NULL){
print_error("Memory allocation error","malloc() failure while trying to allocate space",NULL);
}
}
void int_calloc(int **p2p,size_t order){
*p2p=(int*)calloc(order,sizeof(int));
if(*p2p==NULL){
print_error("Memory allocation error","calloc() failure while trying to allocate space",NULL);
}
}
void int_malloc_ptr(int ***p2p2p,size_t order){
*p2p2p=(int**)malloc(sizeof(int*)*order);
if(*p2p2p==NULL){
print_error("Memory allocation error","malloc() failure while trying to allocate space",NULL);
}
}
void int_free(int **p2p){
if(*p2p==NULL){
print_error("Memory deallocation error","Trying to free unallocated memory",NULL);
}
else{
free(*p2p);
*p2p=NULL;
}
}
void int_free_ptr(int ***p2p2p){
if(*p2p2p==NULL){
print_error("Memory deallocation error","Trying to free unallocated memory",NULL);
}
else{
free(*p2p2p);
*p2p2p=NULL;
}
}