-
Notifications
You must be signed in to change notification settings - Fork 1
/
nv_fix.c
51 lines (45 loc) · 832 Bytes
/
nv_fix.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
#include "nv.h"
#undef malloc
#undef free
char *NV_strncpy(char *dst, const char *src, size_t dst_size, size_t copy_size)
{
int real_size = MIN(dst_size, copy_size + 1);
char *retv = strncpy(dst, src, real_size);
dst[real_size - 1] = 0;
return retv;
}
long NV_strtolSeq(const char **restrict p, int base)
{
char *q;
long n;
n = strtol(*p, &q, base);
*p = q;
return n;
}
int mallocCount = 0;
int NV_getMallocCount()
{
return mallocCount;
}
void *NV_malloc(size_t size)
{
void *retv = malloc(size);
if(!retv){
fputs("NV_malloc: malloc error!\n", stderr);
exit(EXIT_FAILURE);
}
mallocCount++;
//NV_DbgInfo("%s", "malloc!");
return retv;
}
void NV_free(void *p)
{
if(!p){
fputs("NV_malloc: free error!\n", stderr);
exit(EXIT_FAILURE);
}
free(p);
mallocCount--;
//NV_DbgInfo("%s", "free!");
return;
}