add: edit_env_variable
This commit is contained in:
parent
1dd106da2e
commit
982927e0fd
21
src/env/env.c
vendored
21
src/env/env.c
vendored
@ -121,3 +121,24 @@ char *get_env_variable(lst** root, const char* key)
|
|||||||
}
|
}
|
||||||
return (NULL);
|
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
4
src/env/env.h
vendored
@ -7,7 +7,9 @@ typedef struct s_env
|
|||||||
char *value;
|
char *value;
|
||||||
} env;
|
} env;
|
||||||
|
|
||||||
int add_env_variable(lst** root, const char *key, const char *value);
|
|
||||||
lst** env_init(const char **env);
|
lst** env_init(const char **env);
|
||||||
void env_del(void *ptr);
|
void env_del(void *ptr);
|
||||||
|
|
||||||
char *get_env_variable(lst** root, const char* key);
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user