diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2010-12-13 22:53:14 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2010-12-13 22:53:14 +0000 |
commit | 8715247a43c05fe68d6ab2062b0d23c8777c7671 (patch) | |
tree | 5b404cbc9116bcd043e1dc772b3b84af2c4eca62 /cmd-string.c | |
parent | 51487ed22f0acf199f64728f3efc15a3c9ad615f (diff) | |
download | rtmux-8715247a43c05fe68d6ab2062b0d23c8777c7671.tar.gz rtmux-8715247a43c05fe68d6ab2062b0d23c8777c7671.tar.bz2 rtmux-8715247a43c05fe68d6ab2062b0d23c8777c7671.zip |
Read ${X} environment variables in strings and $HOME from the global
environment rather than getenv, this allows them to be updated during
the configuration file.
Diffstat (limited to 'cmd-string.c')
-rw-r--r-- | cmd-string.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/cmd-string.c b/cmd-string.c index 2a5e2b24..9384f9e2 100644 --- a/cmd-string.c +++ b/cmd-string.c @@ -247,9 +247,10 @@ error: char * cmd_string_variable(const char *s, size_t *p) { - int ch, fch; - char *buf, *t; - size_t len; + int ch, fch; + char *buf, *t; + size_t len; + struct environ_entry *envent; #define cmd_string_first(ch) ((ch) == '_' || \ ((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z')) @@ -301,12 +302,11 @@ cmd_string_variable(const char *s, size_t *p) buf = xrealloc(buf, 1, len + 1); buf[len] = '\0'; - if ((t = getenv(buf)) == NULL) { - xfree(buf); - return (xstrdup("")); - } + envent = environ_find(&global_environ, buf); xfree(buf); - return (xstrdup(t)); + if (envent == NULL) + return (xstrdup("")); + return (xstrdup(envent->value)); error: if (buf != NULL) @@ -317,15 +317,17 @@ error: char * cmd_string_expand_tilde(const char *s, size_t *p) { - struct passwd *pw; - char *home, *path, *username; + struct passwd *pw; + struct environ_entry *envent; + char *home, *path, *username; home = NULL; if (cmd_string_getc(s, p) == '/') { - if ((home = getenv("HOME")) == NULL || *home == '\0') { - if ((pw = getpwuid(getuid())) != NULL) - home = pw->pw_dir; - } + envent = environ_find(&global_environ, "HOME"); + if (envent != NULL && *envent->value != '\0') + home = envent->value; + else if ((pw = getpwuid(getuid())) != NULL) + home = pw->pw_dir; } else { cmd_string_ungetc(p); if ((username = cmd_string_string(s, p, '/', 0)) == NULL) |