summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-06-11 15:28:35 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-06-11 21:53:50 -0700
commit7f7272b5b87d3baf8051a6856507b4b2618765c9 (patch)
tree369787f10800fe1d082de27e261b61b03ad54cb4
parent3fbf31290eefc459dcfee379d60d63cc3aef443c (diff)
til: drop open_memstream() in til_get_module_names()
open_memstream() isn't implemented by windows (not even mingw)
-rw-r--r--src/til.c51
1 files 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;
}
© All Rights Reserved