diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2021-04-14 14:27:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-14 14:27:02 -0400 |
commit | 1d8bbdc1a59fd5246ec60bc3db1ece055ef83639 (patch) | |
tree | a2e381c78c1391e278153c807d10a5b55dde3eab /parse.c | |
parent | 53b600e04889dfdcce406cc43e73dc468faf70fa (diff) | |
parent | 475bbc35fbd71f1cb49d04a0daceec214c1344ed (diff) | |
download | bfs-1d8bbdc1a59fd5246ec60bc3db1ece055ef83639.tar.xz |
Merge pull request #72 from markus-oberhumer/allow-empty-less-envvar
parse: launch_pager(): set the LESS environment variable if it is empty.
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -2544,19 +2544,24 @@ static CFILE *launch_pager(pid_t *pid, CFILE *cout) { extern char **environ; char **envp = environ; - if (!getenv("LESS")) { + const char *less = getenv("LESS"); + if (!less || !less[0]) { size_t envc; - for (envc = 0; environ[envc]; ++envc); - ++envc; + for (envc = 0; environ[envc]; ++envc) { } - envp = malloc((envc + 1)*sizeof(*envp)); + envp = malloc((envc + 2)*sizeof(*envp)); if (!envp) { goto fail_ctx; } - memcpy(envp, environ, (envc - 1)*sizeof(*envp)); - envp[envc - 1] = "LESS=FKRX"; - envp[envc] = NULL; + size_t j = 0; + for (size_t i = 0; i < envc; ++i) { + if (strncmp(environ[i], "LESS=", 5) != 0) { + envp[j++] = environ[i]; + } + } + envp[j++] = "LESS=FKRX"; + envp[j] = NULL; } *pid = bfs_spawn(pager, &ctx, argv, envp); |