1 2

[PATCH] Pass environ into mrsh_populate_env

Details
Message ID
<20190118123652.6237-1-sir@cmpwn.com>
Download raw message
Patch +5 -5
---
 include/mrsh/entry.h | 2 +-
 main.c               | 4 +++-
 shell/entry.c        | 4 +---
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/mrsh/entry.h b/include/mrsh/entry.h
index 53389d9..4101907 100644
--- a/include/mrsh/entry.h
+++ b/include/mrsh/entry.h
@@ -20,7 +20,7 @@ char *mrsh_get_ps2(struct mrsh_state *state);
  * Copies variables from the environment and sets up internal variables like
  * IFS, PPID, PWD, etc.
  */
-bool mrsh_populate_env(struct mrsh_state *state);
+bool mrsh_populate_env(struct mrsh_state *state, char **environ);
 
 /**
  * Sources /etc/profile and $HOME/.profile. Note that this behavior is not
diff --git a/main.c b/main.c
index 8958ac0..648d215 100644
--- a/main.c
+++ b/main.c
@@ -14,6 +14,8 @@
 #include <unistd.h>
 #include "frontend.h"
 
+extern char **environ;
+
 int main(int argc, char *argv[]) {
 	struct mrsh_state state = {0};
 	mrsh_state_init(&state);
@@ -24,7 +26,7 @@ int main(int argc, char *argv[]) {
 		return EXIT_FAILURE;
 	}
 
-	if (!mrsh_populate_env(&state)) {
+	if (!mrsh_populate_env(&state, environ)) {
 		return EXIT_FAILURE;
 	}
 
diff --git a/shell/entry.c b/shell/entry.c
index 99df78e..b302911 100644
--- a/shell/entry.c
+++ b/shell/entry.c
@@ -10,8 +10,6 @@
 #include <unistd.h>
 #include "builtin.h"
 
-extern char **environ;
-
 static char *expand_ps(struct mrsh_state *state, const char *ps1) {
 	struct mrsh_parser *parser = mrsh_parser_with_data(ps1, strlen(ps1));
 	struct mrsh_word *word = mrsh_parse_word(parser);
@@ -43,7 +41,7 @@ char *mrsh_get_ps2(struct mrsh_state *state) {
 	return strdup("> ");
 }
 
-bool mrsh_populate_env(struct mrsh_state *state) {
+bool mrsh_populate_env(struct mrsh_state *state, char **environ) {
 	for (size_t i = 0; environ[i] != NULL; ++i) {
 		char *eql = strchr(environ[i], '=');
 		size_t klen = eql - environ[i];
-- 
2.20.1
Details
Message ID
<Fypjv5oyerTYYKOpGdKNiwvkpURPdLlUpZ-1Vgxn55pualnoZD3upgEKE1p5HoQpdPCZxMe83mK_L41BQKMeagLs3xdPk0SBayqs_uf9Lmg=@emersion.fr>
In-Reply-To
<20190118123652.6237-1-sir@cmpwn.com> (view parent)
Download raw message
Pushed:

To git.sr.ht:~emersion/mrsh
   c4de9e0..a0141f7  master -> master

Thanks!