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