mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
env_manip: make it compile
This commit is contained in:
parent
f0a181315b
commit
da447a2491
3 changed files with 60 additions and 6 deletions
|
|
@ -6,26 +6,36 @@
|
|||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/14 18:43:38 by jguelen #+# #+# */
|
||||
/* Updated: 2025/02/15 16:15:12 by jguelen ### ########.fr */
|
||||
/* Updated: 2025/02/18 15:16:58 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "env_manip.h"
|
||||
#include "libft.h"
|
||||
|
||||
/*Designed to get the parameter name for a certain line stored in an envp*/
|
||||
/*
|
||||
** Get the key part of a line of envp
|
||||
**
|
||||
** given that line is of the form key=value, return a string containing key,
|
||||
** which is allocated and must be freed.
|
||||
**
|
||||
** if line is null or is an empty string, return NULL
|
||||
**
|
||||
** if allocation fail, return NULL
|
||||
*/
|
||||
char *envp_get_key(char *line)
|
||||
{
|
||||
char *key;
|
||||
size_t key_len;
|
||||
size_t i;
|
||||
|
||||
key_len = 0;
|
||||
if (!line || !(*line))
|
||||
if (line == NULL || line[0] == '\0')
|
||||
return (NULL);
|
||||
while (line[key_len] != '=')
|
||||
key_len++;
|
||||
key = malloc((key_len + 1) * sizeof(char));
|
||||
i = 0;
|
||||
if (key == NULL)
|
||||
return (NULL);
|
||||
ft_memmove(key, line, key_len);
|
||||
key[key_len] = '\0';
|
||||
return (key);
|
||||
|
|
|
|||
43
src/env_manip.h
Normal file
43
src/env_manip.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* env_manip.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jguelen <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/14 13:46:39 by jguelen #+# #+# */
|
||||
/* Updated: 2025/02/16 12:55:27 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ENV_MANIP_H
|
||||
# define ENV_MANIP_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include "libft.h"
|
||||
|
||||
typedef struct s_env
|
||||
{
|
||||
char *key;
|
||||
char *value;
|
||||
struct s_env *next;
|
||||
} t_env;
|
||||
|
||||
char *envp_get_key(char *line);
|
||||
char *envp_get_val(char *line);
|
||||
void env_rm_entry(t_env **env, char *key);
|
||||
/*WARNING: env_set_entry does NOT check for the actual validity of an
|
||||
identifier (i.e. key) in the sense that it does not check what characters
|
||||
compose it.*/
|
||||
t_env *env_set_entry(t_env **env, char *key, char *value);
|
||||
char *env_get_val(t_env *env, char *key);
|
||||
char **envp_from_env(t_env *env);
|
||||
t_env *env_from_envp(char **envp);
|
||||
/*env_manip_utils*/
|
||||
size_t env_get_size(t_env *env);
|
||||
void env_destroy_node(t_env *node);
|
||||
void env_destroy(t_env **env);
|
||||
void envp_destroy_envp(char **envp);
|
||||
t_env *env_find_node_bykey(t_env *env, char *key);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue