/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cchauvet int ft_file_is_readable(const char *path) { int readable; int fd; fd = open(path, O_RDONLY); if (fd == -1) { ft_eprintf("minishell: %s: No such file or directory\n", path); return (-1); } readable = read(fd, "", 0); if (readable == -1) { ft_eprintf("minishell: %s: Permission denied\n", path); return (-1); } return (fd); } int ft_file_is_writable(const char *path) { int writeable; int fd; fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd == -1) { ft_eprintf("minishell: %s: Permission denied\n", path); return (-1); } writeable = write(fd, "", 0); if (writeable == -1) { ft_eprintf("minishell: %s: Permission denied\n", path); return (-1); } return (fd); } int ft_file_is_appendable(const char *path) { int writeable; int fd; fd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644); if (fd == -1) { ft_eprintf("minishell: %s: Permission denied\n", path); return (-1); } writeable = write(fd, "", 0); if (writeable == -1) { ft_eprintf("minishell: %s: Permission denied\n", path); return (-1); } return (fd); } int ft_file_is_executable(const char *path) { return (access(path, X_OK) == 0); }