#ifdef STB_INCLUDE_IMPLEMENTATION
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
+#ifndef STB_MALLOC
+ #define STB_STDLIB
+ #define STB_MALLOC malloc
+#endif
+
+#ifndef STB_FREE
+ #define STB_STDLIB
+ #define STB_FREE free
+#endif
+
+#ifndef STB_REALLOC
+ #define STB_STDLIB
+ #define STB_REALLOC realloc
+#endif
+
+#ifdef STB_STDLIB
+ #include <stdlib.h>
+#endif
+
static char *stb_include_load_file(char *filename, size_t *plen)
{
char *text;
fseek(f, 0, SEEK_END);
len = (size_t) ftell(f);
if (plen) *plen = len;
- text = (char *) malloc(len+1);
+ text = (char *) STB_MALLOC(len+1);
if (text == 0) return 0;
fseek(f, 0, SEEK_SET);
fread(text, 1, len, f);
static include_info *stb_include_append_include(include_info *array, int len, int offset, int end, char *filename, int next_line)
{
- include_info *z = (include_info *) realloc(array, sizeof(*z) * (len+1));
+ include_info *z = (include_info *)STB_REALLOC(array, sizeof(*z) * (len+1));
z[len].offset = offset;
z[len].end = end;
z[len].filename = filename;
{
int i;
for (i=0; i < len; ++i)
- free(array[i].filename);
- free(array);
+ STB_FREE(array[i].filename);
+ STB_FREE(array);
}
static int stb_include_isspace(int ch)
while (*t != '"' && *t != '\n' && *t != '\r' && *t != 0)
++t;
if (*t == '"') {
- char *filename = (char *) malloc(t-s+1);
+ char *filename = (char *) STB_MALLOC(t-s+1);
memcpy(filename, s, t-s);
filename[t-s] = 0;
s=t;
static char *stb_include_append(char *str, size_t *curlen, char *addstr, size_t addlen)
{
- str = (char *) realloc(str, *curlen + addlen);
+ str = (char *)STB_REALLOC(str, *curlen + addlen);
memcpy(str + *curlen, addstr, addlen);
*curlen += addlen;
return str;
return NULL;
}
text = stb_include_append(text, &textlen, inc, strlen(inc));
- free(inc);
+ STB_FREE(inc);
}
// write out line directive
#ifndef STB_INCLUDE_LINE_NONE
size_t length=0;
for (i=0; i < count; ++i)
length += strlen(strs[i]);
- text = (char *) malloc(length+1);
+ text = (char *) STB_MALLOC(length+1);
length = 0;
for (i=0; i < count; ++i) {
strcpy(text + length, strs[i]);
length += strlen(strs[i]);
}
result = stb_include_string(text, inject, path_to_includes, filename, error);
- free(text);
+ STB_FREE(text);
return result;
}
return 0;
}
result = stb_include_string(text, inject, path_to_includes, filename, error);
- free(text);
+ STB_FREE(text);
return result;
}