path is now an owned string since we actually need to make a copy that's an array
This commit is contained in:
parent
118f706b00
commit
ab3ef8bb8b
4 changed files with 21 additions and 10 deletions
|
|
@ -6,6 +6,7 @@
|
|||
struct msh_lexer_t {
|
||||
msh_lexer_item_list *item_list_head;
|
||||
msh_lexer_item_list *item_list_cur;
|
||||
char *path;
|
||||
};
|
||||
|
||||
msh_lexer *msh_lexer_new() {
|
||||
|
|
@ -17,6 +18,8 @@ msh_lexer *msh_lexer_new() {
|
|||
|
||||
l->item_list_cur = l->item_list_head;
|
||||
|
||||
l->path = msh_env_get_path();
|
||||
|
||||
return l;
|
||||
};
|
||||
|
||||
|
|
@ -125,7 +128,6 @@ void msh_lexer_execute(msh_lexer *lexer) {
|
|||
SIZE_TYPE args_size = 0;
|
||||
char **args = 0;
|
||||
int is_first_arg = 0, i = 0, n = 0, j = 0, counter = 0, exec_success = 0;
|
||||
const char *path = msh_env_get_path();
|
||||
char *full_path;
|
||||
|
||||
while (list != 0) {
|
||||
|
|
@ -174,8 +176,8 @@ void msh_lexer_execute(msh_lexer *lexer) {
|
|||
i = 0, n = 0, j = 0;
|
||||
full_path = msh_allocate(1024);
|
||||
while (1) {
|
||||
full_path[n++] = path[j];
|
||||
if (path[j] == '\0') {
|
||||
full_path[n++] = lexer->path[j];
|
||||
if (lexer->path[j] == '\0') {
|
||||
full_path[n - 1] = msh_path_seperator;
|
||||
for (i = 0; cmd[i] != 0; i++) {
|
||||
full_path[i + n] = cmd[i];
|
||||
|
|
@ -224,6 +226,7 @@ void msh_lexer_flush(msh_lexer *lexer) {
|
|||
}
|
||||
|
||||
void msh_lexer_free(msh_lexer *lexer) {
|
||||
msh_deallocate(lexer->path);
|
||||
msh_deallocate(lexer->item_list_head);
|
||||
msh_deallocate(lexer);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,9 +22,7 @@ void msh_linux_env_map_init() {
|
|||
while (1) {
|
||||
msh_file_read(env_file, &ch, 1);
|
||||
|
||||
if (ch == ':' && env_item_tail->is_path == 1) {
|
||||
file_buf[cur++] = '\0';
|
||||
} else if (ch != '=') {
|
||||
if (ch != '=') {
|
||||
file_buf[cur++] = ch;
|
||||
} else {
|
||||
file_buf[cur++] = '\0';
|
||||
|
|
@ -86,12 +84,21 @@ const char *msh_env_get(const char *key) {
|
|||
return 0;
|
||||
};
|
||||
|
||||
const char *msh_env_get_path() {
|
||||
char *msh_env_get_path() {
|
||||
msh_linux_env_item *env_item_tail = env_items;
|
||||
|
||||
while (env_item_tail->next != 0) {
|
||||
if (env_item_tail->is_path) {
|
||||
return env_item_tail->value;
|
||||
char *newenv = msh_allocate(env_item_tail->value_len);
|
||||
char *newenv_ptr = newenv, *newval_ptr = env_item_tail->value;
|
||||
while (*newval_ptr != '\0') {
|
||||
*newenv_ptr = *newval_ptr++;
|
||||
if (*newenv_ptr == ':') {
|
||||
*newenv_ptr = '\0';
|
||||
}
|
||||
newenv_ptr++;
|
||||
}
|
||||
return newenv;
|
||||
}
|
||||
env_item_tail = env_item_tail->next;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ int msh_execute(char *cmd, char **args) {
|
|||
fork = (SIZE_TYPE)SYSCALL(fork, 0);
|
||||
|
||||
if (fork == 0) {
|
||||
char **env_translated = 0;
|
||||
const char **env_translated = 0;
|
||||
SIZE_TYPE env_translated_size = 0;
|
||||
int ret, i = 0, n = 0;
|
||||
msh_linux_env_item *item_list = env_items;
|
||||
|
|
|
|||
|
|
@ -105,8 +105,9 @@ void msh_env_set(const char *key, char *value);
|
|||
/*
|
||||
* Gets a NULL-delimited string representing the folders to search for in the
|
||||
* path, ending in two NULLs.
|
||||
* The resulting string is owned by the caller and must be freed appropriately.
|
||||
*/
|
||||
const char *msh_env_get_path();
|
||||
char *msh_env_get_path();
|
||||
|
||||
/*
|
||||
* System path seperator
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue