use garbage collection
[iwhd.git] / gc-wrap.h
blob70c4b9df17b46908c7ff444632793e2e964a623a
1 #include <string.h>
2 #define GC_THREADS
3 #include "gc.h"
5 #ifndef __cplusplus
6 # define malloc(n) GC_MALLOC(n)
7 # define calloc(m,n) GC_MALLOC((m)*(n))
8 # define free(p) GC_FREE(p)
9 # define realloc(p,n) GC_REALLOC((p),(n))
10 #endif
12 static inline char *
13 my_strdup (char const *s)
15 size_t len = strlen (s);
16 void *t = GC_MALLOC (len + 1);
17 if (t == NULL)
18 return NULL;
19 return (char *) memcpy (t, s, len + 1);
21 # undef strdup
22 # define strdup(s) my_strdup(s)
24 static inline char *
25 my_strndup (char const *s, size_t n)
27 size_t len = strnlen (s, n);
28 char *t = (char *) GC_MALLOC (len + 1);
29 if (t == NULL)
30 return NULL;
31 t[len] = '\0';
32 return (char *) memcpy (t, s, len);
34 # undef strndup
35 # define strndup(s, n) my_strndup(s, n)