mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
WIP: env: getting key and value from an envp entry
This commit is contained in:
parent
eaa1afda5f
commit
f0a181315b
1 changed files with 46 additions and 0 deletions
46
src/env_get_set.c
Normal file
46
src/env_get_set.c
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* env_get_set.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/02/14 18:43:38 by jguelen #+# #+# */
|
||||||
|
/* Updated: 2025/02/15 16:15:12 by jguelen ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "env_manip.h"
|
||||||
|
|
||||||
|
/*Designed to get the parameter name for a certain line stored in an envp*/
|
||||||
|
char *envp_get_key(char *line)
|
||||||
|
{
|
||||||
|
char *key;
|
||||||
|
size_t key_len;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
key_len = 0;
|
||||||
|
if (!line || !(*line))
|
||||||
|
return (NULL);
|
||||||
|
while (line[key_len] != '=')
|
||||||
|
key_len++;
|
||||||
|
key = malloc((key_len + 1) * sizeof(char));
|
||||||
|
i = 0;
|
||||||
|
ft_memmove(key, line, key_len);
|
||||||
|
key[key_len] = '\0';
|
||||||
|
return (key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Designed to get the value part of an envp entry*/
|
||||||
|
char *envp_get_val(char *line)
|
||||||
|
{
|
||||||
|
char *value_string;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
tmp = ft_strchr(line, '=');
|
||||||
|
if (!tmp)
|
||||||
|
return (NULL);
|
||||||
|
tmp++;
|
||||||
|
value_string = ft_strdup(tmp);
|
||||||
|
return (value_string);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue