summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-04-14 14:27:02 -0400
committerGitHub <noreply@github.com>2021-04-14 14:27:02 -0400
commit1d8bbdc1a59fd5246ec60bc3db1ece055ef83639 (patch)
treea2e381c78c1391e278153c807d10a5b55dde3eab
parent53b600e04889dfdcce406cc43e73dc468faf70fa (diff)
parent475bbc35fbd71f1cb49d04a0daceec214c1344ed (diff)
downloadbfs-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.
-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);