From 7f7272b5b87d3baf8051a6856507b4b2618765c9 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 11 Jun 2023 15:28:35 -0700 Subject: til: drop open_memstream() in til_get_module_names() open_memstream() isn't implemented by windows (not even mingw) --- src/til.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/til.c b/src/til.c index 8b9e382..4241c12 100644 --- a/src/til.c +++ b/src/til.c @@ -173,39 +173,44 @@ char * til_get_module_names(unsigned flags_excluded, const char **exclusions) { const til_module_t **modules; size_t n_modules; - char *buf; size_t bufsz; - FILE *fp; - - /* FIXME TODO: more unportable memstream! */ - fp = open_memstream(&buf, &bufsz); - if (!fp) - return NULL; + char *buf; til_get_modules(&modules, &n_modules); - for (size_t i = 0, j = 0; i < n_modules; i++) { - const til_module_t *mod = modules[i]; - const char **exclusion = exclusions; - if ((mod->flags & flags_excluded)) - continue; + for (buf = NULL, bufsz = sizeof('\0');;) { + for (size_t i = 0, j = 0, p = 0; i < n_modules; i++) { + const til_module_t *mod = modules[i]; + const char **exclusion = exclusions; - while (*exclusion) { - if (!strcmp(*exclusion, mod->name)) - break; + if ((mod->flags & flags_excluded)) + continue; - exclusion++; + while (*exclusion) { + if (!strcmp(*exclusion, mod->name)) + break; + + exclusion++; + } + + if (*exclusion) + continue; + + if (!buf) + bufsz += snprintf(NULL, 0, "%s%s", j ? "," : "", mod->name); + else + p += snprintf(&buf[p], bufsz - p, "%s%s", j ? "," : "", mod->name); + + j++; } - if (*exclusion) - continue; + if (buf) + return buf; - fprintf(fp, "%s%s", j ? "," : "", mod->name); - j++; + buf = calloc(1, bufsz); + if (!buf) + return NULL; } - fclose(fp); - - return buf; } -- cgit v1.2.3