Browse Source

fix cd error is not home and return for errors commands

master
narnaud 3 years ago
parent
commit
1d849c4feb
  1. 14
      built-in.c
  2. 4
      caller.c
  3. 6
      errors.c
  4. 4
      minishell.h

14
built-in.c

@ -6,7 +6,7 @@
/* By: mea <mea@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/06 09:02:57 by narnaud #+# #+# */
/* Updated: 2022/05/17 15:38:18 by mea ### ########.fr */
/* Updated: 2022/05/17 17:28:52 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -74,8 +74,10 @@ int ft_pwd(t_command *cmd)
return (0);
}
int ft_cd(t_command *cmd)
int ft_cd(t_datas *datas, t_command *cmd)
{
char *home;
if (cmd->argv[1])
{
if (access(cmd->argv[1], X_OK))
@ -88,7 +90,13 @@ int ft_cd(t_command *cmd)
return (0);
}
else
chdir(getenv("HOME"));
{
home = get_var_value(datas, "HOME", 5);
if (*home)
chdir(home);
else
return (cmd_error("cd", "HOME not set"));
}
return (0);
}

4
caller.c

@ -6,7 +6,7 @@
/* By: mea <mea@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/03 11:48:16 by narnaud #+# #+# */
/* Updated: 2022/05/17 16:28:32 by narnaud ### ########.fr */
/* Updated: 2022/05/17 17:26:25 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,7 +22,7 @@ int call_builtin(t_datas *datas, t_command *cmd)
else if (ft_strncmp(cmd->argv[0], "pwd", 4) == 0)
return (ft_pwd(cmd));
else if (ft_strncmp(cmd->argv[0], "cd", 3) == 0)
return (ft_cd(cmd));
return (ft_cd(datas, cmd));
else if (ft_strncmp(cmd->argv[0], "export", 7) == 0)
return (ft_export(datas, cmd));
else if (ft_strncmp(cmd->argv[0], "unset", 6) == 0)

6
errors.c

@ -6,7 +6,7 @@
/* By: mea <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/06 13:15:59 by narnaud #+# #+# */
/* Updated: 2022/05/17 09:59:56 by narnaud ### ########.fr */
/* Updated: 2022/05/17 17:24:09 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ int file_error(char *cmd, char *file, char *msg)
ft_putstr_fd(": ", 2);
ft_putstr_fd(msg, 2);
ft_putchar_fd('\n', 2);
return (0);
return (1);
}
int cmd_error(char *cmd, char *msg)
@ -31,7 +31,7 @@ int cmd_error(char *cmd, char *msg)
ft_putstr_fd(": ", 2);
ft_putstr_fd(msg, 2);
ft_putchar_fd('\n', 2);
return (0);
return (1);
}
int is_valid_identifier(char *ident)

4
minishell.h

@ -6,7 +6,7 @@
/* By: mea <mea@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */
/* Updated: 2022/05/17 15:55:14 by mea ### ########.fr */
/* Updated: 2022/05/17 17:25:53 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
@ -68,7 +68,7 @@ int is_valid_identifier(char *ident);
int is_builtin(char *cmd);
int ft_echo(t_command *cmd);
int ft_pwd(t_command *cmd);
int ft_cd(t_command *cmd);
int ft_cd(t_datas *datas, t_command *cmd);
int ft_exit(t_datas *datas, t_command *cmd);
// ----------------------------------Env.c

Loading…
Cancel
Save