diff options
author | Markus F.X.J. Oberhumer <markus@oberhumer.com> | 2021-04-14 19:42:40 +0200 |
---|---|---|
committer | Markus F.X.J. Oberhumer <markus@oberhumer.com> | 2021-04-14 20:13:42 +0200 |
commit | 475bbc35fbd71f1cb49d04a0daceec214c1344ed (patch) | |
tree | a2e381c78c1391e278153c807d10a5b55dde3eab | |
parent | 53b600e04889dfdcce406cc43e73dc468faf70fa (diff) |
parse: launch_pager(): set the LESS environment variable if it is empty.
-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); |