summaryrefslogtreecommitdiff
path: root/src/common/malloc.c
blob: 089a9db1897f57b7a65e519b3c1bfac016ffb3d1 (plain) (blame)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "malloc.h"

#if !defined(DMALLOC) && !defined(GCOLLECT) && !defined(BCHECK)

void* aMalloc_( size_t size, const char *file, int line, const char *func )
{
	void *ret;

//	printf("%s:%d: in func %s: malloc %d\n",file,line,func,size);
	ret=malloc(size);
	if(ret==NULL){
		printf("%s:%d: in func %s: malloc error out of memory!\n",file,line,func);
		exit(1);

	}
	return ret;
}
void* aCalloc_( size_t num, size_t size, const char *file, int line, const char *func )
{
	void *ret;

//	printf("%s:%d: in func %s: calloc %d %d\n",file,line,func,num,size);
	ret=calloc(num,size);
	if(ret==NULL){
		printf("%s:%d: in func %s: calloc error out of memory!\n",file,line,func);
		exit(1);

	}
	return ret;
}

void* aRealloc_( void *p, size_t size, const char *file, int line, const char *func )
{
	void *ret;

//	printf("%s:%d: in func %s: realloc %p %d\n",file,line,func,p,size);
	ret=realloc(p,size);
	if(ret==NULL){
		printf("%s:%d: in func %s: realloc error out of memory!\n",file,line,func);
		exit(1);

	}
	return ret;
}

#endif


#if defined(GCOLLECT)

void * _bcallocA(size_t size, size_t cnt) {
	void *ret = aMallocA(size * cnt);
	memset(ret, 0, size * cnt);
	return ret;
}

void * _bcalloc(size_t size, size_t cnt) {
	void *ret = aMalloc(size * cnt);
	memset(ret, 0, size * cnt);
	return ret;
}
#endif

char * _bstrdup(const char *chr) {
	int len = strlen(chr);
	char *ret = (char*)aMalloc(len + 1);
	strcpy(ret, chr);
	return ret;
}