summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus F.X.J. Oberhumer <markus@oberhumer.com>2021-04-14 19:42:40 +0200
committerMarkus F.X.J. Oberhumer <markus@oberhumer.com>2021-04-14 20:13:42 +0200
commit475bbc35fbd71f1cb49d04a0daceec214c1344ed (patch)
treea2e381c78c1391e278153c807d10a5b55dde3eab
parent53b600e04889dfdcce406cc43e73dc468faf70fa (diff)
downloadbfs-475bbc35fbd71f1cb49d04a0daceec214c1344ed.tar.xz
parse: launch_pager(): set the LESS environment variable if it is empty.
-rw-r--r--parse.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/parse.c b/parse.c
index 4d4702c..2475290 100644
--- a/parse.c
+++ b/parse.c
@@ -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);