From 5dbce99ee2f58083fbffe8732fbab40007df0223 Mon Sep 17 00:00:00 2001 From: Tanguy MAZE Date: Fri, 14 Feb 2020 12:31:39 +0100 Subject: [PATCH] corrected make' --- Makefile | 1 - libft/includes/libft.h | 4 ++-- libft/srcs/ft_envnew.c | 4 ++-- srcs/cmd_cd_utils.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 srcs/cmd_cd_utils.c diff --git a/Makefile b/Makefile index 23fb8cd..4f3b2b0 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,6 @@ SRC = main.c \ put_error_cd.c \ ms_exec_utils.c \ def_env.c \ - envnew.c \ check_path_slash_cd.c OBJ = $(SRC:.c=.o) diff --git a/libft/includes/libft.h b/libft/includes/libft.h index 0d6af2f..a27d4db 100644 --- a/libft/includes/libft.h +++ b/libft/includes/libft.h @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */ -/* Updated: 2020/02/07 15:25:43 by tmaze ### ########.fr */ +/* Updated: 2020/02/14 12:28:38 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -374,7 +374,7 @@ int ft_putendl_fd2(char const *s, int fd); void ft_envdelelem(t_env **elem); void ft_envdel(t_env **env); t_env *ft_envnew(char *env); -t_env *ft_envnewinit(char *key, char *val, t_env *env); +t_env *ft_envnewinit(char *key, char *val); t_env *ft_envaddend(t_env **alst, t_env *new); t_env *ft_envgetelem(char *key, t_env *env); char *ft_envtochar(t_env *env); diff --git a/libft/srcs/ft_envnew.c b/libft/srcs/ft_envnew.c index 1d70b74..25a88d7 100644 --- a/libft/srcs/ft_envnew.c +++ b/libft/srcs/ft_envnew.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/12/05 14:54:55 by tmaze #+# #+# */ -/* Updated: 2019/12/05 17:12:59 by tmaze ### ########.fr */ +/* Updated: 2020/02/14 12:28:20 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ t_env *ft_envnew(char *env) return (ret); } -t_env *ft_envnewinit(char *key, char *val, t_env *env) +t_env *ft_envnewinit(char *key, char *val) { t_env *ret; int i; diff --git a/srcs/cmd_cd_utils.c b/srcs/cmd_cd_utils.c new file mode 100644 index 0000000..57b80d0 --- /dev/null +++ b/srcs/cmd_cd_utils.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cmd_cd_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaze +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 11:55:54 by tmaze #+# #+# */ +/* Updated: 2020/02/14 11:56:53 by tmaze ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_env *cd_updateenv(char *key, char *val, t_env **env) +{ + t_env *tmp; + + if ((tmp = ft_envgetelem(key, *env)) != NULL) + ft_envupdate(key, *env, val); + else if ((tmp = (t_env*)ft_memalloc(sizeof(t_env))) != NULL) + { + if ((tmp->key = ft_strdup(key)) == NULL) + ft_envdelelem(&tmp); + if (tmp && (tmp->val = ft_strdup(val)) == NULL) + ft_envdelelem(&tmp); + if (tmp) + ft_envaddend(env, tmp); + } + return (tmp); +}