/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* b_sqb_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include #include #include "d_define.h" static t_bool b_file_tests_one(uint8_t id, struct stat *st) { if (id == FT_ID_SQB_B && S_ISBLK(st->st_mode) == 1) return (TRUE); else if (id == FT_ID_SQB_C && S_ISCHR(st->st_mode) == 1) return (TRUE); else if (id == FT_ID_SQB_D && S_ISDIR(st->st_mode) == 1) return (TRUE); else if (id == FT_ID_SQB_F && S_ISREG(st->st_mode) == 1) return (TRUE); else if ((id == FT_ID_SQB_H || id == FT_ID_SQB_L_MAJ) && S_ISLNK(st->st_mode) == 1) return (TRUE); else if (id == FT_ID_SQB_P && S_ISFIFO(st->st_mode) == 1) return (TRUE); return (FALSE); } uint8_t b_sqb_file_tests(uint8_t id, char *argv[]) { struct stat st; int32_t fd; if ((fd = open(argv[1], O_RDONLY)) == -1) return (1); if (id == FT_ID_SQB_E) { close(fd); return (0); } fstat(fd, &st); close(fd); if (b_file_tests_one(id, &st) == TRUE) return (0); return (1); }