/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* check_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lfirmin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/08/22 15:07:29 by lfirmin #+# #+# */ /* Updated: 2025/10/07 10:11:50 by lfirmin ### ########.fr */ /* */ /* ************************************************************************** */ #include "cub.h" int check_file(char *map_path, t_data_parsing *parsing) { if (!map_path) return (ft_error(ERROR_EMPT_PATH), 1); if (check_extension(map_path)) return (1); parsing->fd_map = open(map_path, O_RDONLY); if (parsing->fd_map < 0) return (perror("Error\n"), 1); parsing->fd_map_dup = open(map_path, O_RDONLY); if (parsing->fd_map_dup < 0) return (perror("Error\n"), 1); return (0); } int check_extension(char *map_path) { int len_map_path; if (!map_path) return (1); len_map_path = ft_strlen(map_path); if (len_map_path < 4) return (ft_error(ERROR_EXT), 1); if (ft_strcmp(map_path + len_map_path - 4, ".cub") != 0) return (ft_error(ERROR_EXT), 1); return (0); }