diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 2fcdce1..903d597 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -13,7 +13,7 @@ msh_lexer msh_lexer_new() { l.item_list_cur = l.item_list_head; - l.path = msh_env_get_path(); + l.path = msh_env_get_path(&l.path_count); return l; }; @@ -148,7 +148,7 @@ static int do_exec(msh_lexer *lexer, char *cmd, char **args, int *n, /* loop through all the path entries and check if the file exists in them. */ i = 0, *n = 0, j = 0; - while (1) { + while (j >= lexer->path_count) { full_path[*n] = lexer->path[j]; *n += 1; if (lexer->path[j] == '\0') { diff --git a/src/lexer/lexer.h b/src/lexer/lexer.h index b5da7cb..97f8b2a 100644 --- a/src/lexer/lexer.h +++ b/src/lexer/lexer.h @@ -29,6 +29,7 @@ typedef struct msh_lexer_t { msh_lexer_item_list *item_list_head; msh_lexer_item_list *item_list_cur; char *path; + SIZE_TYPE path_count; } msh_lexer; msh_lexer msh_lexer_new(); diff --git a/src/system/linux/env.c b/src/system/linux/env.c index c97324a..eb23a3c 100644 --- a/src/system/linux/env.c +++ b/src/system/linux/env.c @@ -85,7 +85,7 @@ const char *msh_env_get(const char *key) { return 0; }; -char *msh_env_get_path() { +char *msh_env_get_path(SIZE_TYPE *num) { msh_linux_env_item *env_item_tail = &env_items; while (env_item_tail->next != 0) { @@ -98,6 +98,7 @@ char *msh_env_get_path() { *newenv_ptr = '\0'; } newenv_ptr++; + *num += 1; } return newenv; } diff --git a/src/system/system.h b/src/system/system.h index 55f4b8d..78b05b0 100644 --- a/src/system/system.h +++ b/src/system/system.h @@ -133,7 +133,7 @@ void msh_env_set(const char *key, char *value); * path, ending in two NULLs. * The resulting string is owned by the caller and must be freed appropriately. */ -char *msh_env_get_path(); +char *msh_env_get_path(SIZE_TYPE *num); /* * System path seperator