bug fix env -i && cd error message

This commit is contained in:
Tanguy MAZE 2020-02-14 12:22:35 +01:00
parent 7db099a010
commit b9c1a344b2
6 changed files with 31 additions and 10 deletions

View File

@ -6,7 +6,7 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/03/27 16:51:02 by tmaze #+# #+# #
# Updated: 2020/02/01 15:54:10 by tmaze ### ########.fr #
# Updated: 2020/02/14 11:56:31 by tmaze ### ########.fr #
# #
#******************************************************************************#
@ -38,15 +38,17 @@ INCDIR = includes libft/includes
# Source files
SRC = main.c \
cmd_env.c \
cmd_setenv.c \
cmd_unsetenv.c \
cmd_setenv.c \
cmd_unsetenv.c \
cmd_cd.c \
cmd_cd_utils.c \
cmd_echo.c \
ms_exec.c \
ms_ext.c \
put_error_cd.c \
ms_exec_utils.c \
put_error_cd.c \
ms_exec_utils.c \
def_env.c \
envnew.c \
check_path_slash_cd.c
OBJ = $(SRC:.c=.o)

View File

@ -50,4 +50,6 @@ t_env *def_env(void);
void *return_null(char *msg);
t_env *cd_updateenv(char *key, char *val, t_env **env);
#endif

View File

@ -374,6 +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_envaddend(t_env **alst, t_env *new);
t_env *ft_envgetelem(char *key, t_env *env);
char *ft_envtochar(t_env *env);

View File

@ -27,3 +27,18 @@ t_env *ft_envnew(char *env)
ft_envdelelem(&ret);
return (ret);
}
t_env *ft_envnewinit(char *key, char *val, t_env *env)
{
t_env *ret;
int i;
i = 0;
ret = NULL;
if ((ret = (t_env*)ft_memalloc(sizeof(t_env))) != NULL)
if ((ret->key = ft_strdup(key)) != NULL)
if ((ret->val = ft_strdup(val)) != NULL)
return (ret);
ft_envdelelem(&ret);
return (ret);
}

View File

@ -25,8 +25,8 @@ int cmd_cd_update_env(char *path, t_env **env, char opt)
if (getcwd(p_path, 4096) == NULL || (oldpwd = ft_strdup(pwd->val)) == NULL
|| ft_realpath(path, &c_path) == NULL)
return (put_error_cd2(path, "error"));
if (ft_envupdate("PWD", *env, ((opt == 'P') ? p_path : c_path)) == NULL
|| ft_envupdate("OLDPWD", *env, oldpwd) == NULL)
if (cd_updateenv("PWD", ((opt == 'P') ? p_path : c_path), env) == NULL
|| cd_updateenv("OLDPWD", oldpwd, env) == NULL)
{
ft_strdel(&oldpwd);
ft_strdel(&c_path);

View File

@ -78,14 +78,15 @@ int cleanup(char **argv, t_env *env)
return (0);
}
int main(void)
int main(int ac , char **av, char **envp)
{
extern char **environ;
char **argv;
t_env *env;
char *cmd;
if ((env = env2lst(environ)) == NULL)
(void)ac;
(void)av;
if ((env = env2lst(envp)) == NULL)
return (2);
while (1)
{