diff --git a/linkedlist.c b/linkedlist.c index 0778e6c..5d560d6 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -2,6 +2,7 @@ envstruct *insert_end(envstruct *head, char *key, char *value) { + envstruct *curr = head; envstruct *new_node = malloc(sizeof(envstruct)); if (new_node == NULL) @@ -18,8 +19,6 @@ envstruct *insert_end(envstruct *head, char *key, char *value) return (new_node); } - envstruct *curr; - curr = head; while (curr->next != NULL) { @@ -67,14 +66,14 @@ char *get_value(envstruct *head, char *key) */ int remove_value(envstruct **head, char *key) { + envstruct *curr = *head; + envstruct *prev = NULL; + if (head == NULL || *head == NULL) { return (1); } - envstruct *curr = *head; - envstruct *prev = NULL; - while (curr != NULL) { if (strcmp(curr->key, key) == 0) diff --git a/main.c b/main.c index 2f7a06c..010eae7 100644 --- a/main.c +++ b/main.c @@ -10,9 +10,10 @@ char *lineptr; */ int main(void) { + envstruct *head = NULL; + atexit(clean_up); signal(SIGINT, sig_int_handler); - envstruct *head = NULL; while (1) { @@ -235,7 +236,9 @@ void env_cmd(void) */ void init_env_list(envstruct *head) { - while (*environ != NULL) + int i = 0; + + while (environ[i] != NULL) { char *key = strtok(*environ, "="), *val = NULL; @@ -246,7 +249,7 @@ void init_env_list(envstruct *head) } head = insert_end(head, key, val); - *environ++; + i++; } } diff --git a/shell b/shell index 98ade31..eb43a92 100755 Binary files a/shell and b/shell differ