dcbde236 |
1 | /* |
2 | * PuTTY memory-handling header. |
3 | */ |
4 | |
5 | #ifndef PUTTY_PUTTYMEM_H |
6 | #define PUTTY_PUTTYMEM_H |
7 | |
32874aea |
8 | #include <stddef.h> /* for size_t */ |
9 | #include <string.h> /* for memcpy() */ |
db9c0f86 |
10 | |
11 | |
dcbde236 |
12 | /* #define MALLOC_LOG do this if you suspect putty of leaking memory */ |
13 | #ifdef MALLOC_LOG |
14 | #define smalloc(z) (mlog(__FILE__,__LINE__), safemalloc(z)) |
15 | #define srealloc(y,z) (mlog(__FILE__,__LINE__), saferealloc(y,z)) |
16 | #define sfree(z) (mlog(__FILE__,__LINE__), safefree(z)) |
17 | void mlog(char *, int); |
18 | #else |
19 | #define smalloc safemalloc |
20 | #define srealloc saferealloc |
21 | #define sfree safefree |
22 | #endif |
23 | |
24 | void *safemalloc(size_t); |
25 | void *saferealloc(void *, size_t); |
26 | void safefree(void *); |
27 | |
db9c0f86 |
28 | |
29 | /* smalloc a thing */ |
30 | #define smalloca(type) ((type *) smalloc (sizeof (type))) |
31 | /* smalloc a copy of a thing */ |
32 | #define smallocc(ptr) memcpy (smalloc (sizeof (*ptr)), ptr, sizeof (*ptr)) |
33 | /* smalloc n things */ |
34 | #define smallocn(n,type) ((type *) smalloc ((n) * sizeof (type))) |
35 | |
36 | |
dcbde236 |
37 | #endif |