From 730fb6b3ea0fbd79eed50d6dbc38787c3cc91412 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 2 Jul 2024 00:16:46 +0200 Subject: Make strspushenv() expand the value of the EV --- cbs.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cbs.h b/cbs.h index 668db72..0f8551c 100644 --- a/cbs.h +++ b/cbs.h @@ -215,10 +215,22 @@ strspushenv(struct strs *xs, const char *ev, char **ys, size_t n) { /* NOTE: Do your best to NOT modify any pushed envvar! */ char *p = getenv(ev); - if (p == NULL || *p == 0) + if (p == NULL || *p == 0) { strspush(xs, ys, n); - else - strspush(xs, &p, 1); + return; + } + + wordexp_t we; + assert(wordexp(p, &we, WRDE_NOCMD) == 0); + + /* TODO: Memory leak! */ + for (size_t i = 0; i < we.we_wordc; i++) { + char *w = strdup(we.we_wordv[i]); + assert(w != NULL); + strspushl(xs, w); + } + + wordfree(&we); } bool @@ -433,11 +445,14 @@ pcquery(struct strs *xs, const char *lib, int flags) char **words = malloc(sizeof(char *) * we.we_wordc); assert(words != NULL); + + /* TODO: Memory leak! */ for (size_t i = 0; i < we.we_wordc; i++) assert((words[i] = strdup(we.we_wordv[i])) != NULL); strspush(xs, words, we.we_wordc); wordfree(&we); + free(words); free(buf); return true; } -- cgit v1.2.3