add: edit_env_variable

This commit is contained in:
starnakin 2023-06-29 13:42:05 +02:00
parent 1dd106da2e
commit 982927e0fd
2 changed files with 24 additions and 1 deletions

21
src/env/env.c vendored
View File

@ -121,3 +121,24 @@ char *get_env_variable(lst** root, const char* key)
}
return (NULL);
}
int edit_env_variable(lst** root, const char *key, const char *new_value)
{
lst* current = *root;
env* content;
while (current != NULL)
{
content = current->content;
if (strcmp(content->key, key) == 0)
{
free(content->value);
content->value = strdup(new_value);
if (content->value == NULL)
return (2);
return (0);
}
current = current->next;
}
return (1);
}

4
src/env/env.h vendored
View File

@ -7,7 +7,9 @@ typedef struct s_env
char *value;
} env;
int add_env_variable(lst** root, const char *key, const char *value);
lst** env_init(const char **env);
void env_del(void *ptr);
char *get_env_variable(lst** root, const char* key);
int add_env_variable(lst** root, const char *key, const char *value);
int edit_env_variable(lst** root, const char *key, const char *new_value);