X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=dep%2Fstb%2Fstb_include.h;fp=dep%2Fstb%2Fstb_include.h;h=6a90097144265a958bfa25b9fcb8dadf8bfa3019;hb=5729777dfec3f9f12c1821aa50db6a3c04cc359c;hp=c5db20138a23b0a760252960966c6720f5f05153;hpb=6aeba08ad9ad8bdecafcfd9f946173e99a84fc59;p=vg.git diff --git a/dep/stb/stb_include.h b/dep/stb/stb_include.h index c5db201..6a90097 100644 --- a/dep/stb/stb_include.h +++ b/dep/stb/stb_include.h @@ -53,9 +53,27 @@ char *stb_include_file(char *filename, char *inject, char *path_to_includes, cha #ifdef STB_INCLUDE_IMPLEMENTATION #include -#include #include +#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 +#endif + static char *stb_include_load_file(char *filename, size_t *plen) { char *text; @@ -65,7 +83,7 @@ static char *stb_include_load_file(char *filename, size_t *plen) 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); @@ -84,7 +102,7 @@ typedef struct 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; @@ -96,8 +114,8 @@ static void stb_include_free_includes(include_info *array, int len) { 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) @@ -130,7 +148,7 @@ static int stb_include_find_includes(char *text, include_info **plist) 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; @@ -175,7 +193,7 @@ static void stb_include_itoa(char str[9], int n) 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; @@ -228,7 +246,7 @@ char *stb_include_string(char *str, char *inject, char *path_to_includes, char * 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 @@ -258,14 +276,14 @@ char *stb_include_strings(char **strs, int count, char *inject, char *path_to_in 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; } @@ -281,7 +299,7 @@ char *stb_include_file(char *filename, char *inject, char *path_to_includes, cha return 0; } result = stb_include_string(text, inject, path_to_includes, filename, error); - free(text); + STB_FREE(text); return result; }