/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* built-in.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/06 09:02:57 by narnaud #+# #+# */ /* Updated: 2022/05/03 18:18:23 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" int ft_echo(t_command *cmd) { int no_nl; no_nl = 0; if (*(++cmd->argv)) { if (ft_strncmp(*(cmd->argv), "-n", 3) == 0 && cmd->argv++) no_nl = 1; while (*(cmd->argv)) { ft_putstr_fd(*(cmd->argv), 1); if (*(++cmd->argv)) ft_putstr_fd(" ", 1); } } if (!no_nl) ft_putstr_fd("\n", 1); return (0); } int ft_pwd(t_command *cmd) { char *dir; (void)cmd; dir = ft_calloc(PATHS_MAX_SIZE, sizeof(char)); getcwd(dir, PATHS_MAX_SIZE); ft_putstr_fd(dir, 1); ft_putstr_fd("\n", 1); free(dir); return (0); } int ft_cd(t_command *cmd) { if (cmd->argv[1]) { if (access(cmd->argv[1], X_OK)) { printf("Minishell: %s: %s: Permission denied\n", cmd->argv[0], cmd->argv[1]); return (0); } else if (access(cmd->argv[1], F_OK)) { printf("Minishell: %s: %s: Not a directory\n", cmd->argv[0], cmd->argv[1]); return (0); } chdir(cmd->argv[1]); return (1); } else { chdir(getenv("HOME")); } return (0); } int close_minishell(int exit_code) { exit(exit_code); }