diff options
Diffstat (limited to 'src/b_sqb_file.c')
-rw-r--r-- | src/b_sqb_file.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/b_sqb_file.c b/src/b_sqb_file.c index d6d07e0..b69f160 100644 --- a/src/b_sqb_file.c +++ b/src/b_sqb_file.c @@ -11,29 +11,50 @@ /* ************************************************************************** */ #include <sys/stat.h> +#include <libft.h> +#include <fcntl.h> +#include <unistd.h> #include <stdint.h> -static uint8_t +#include "d_define.h" + +static t_bool b_file_tests_one(uint8_t id, struct stat *st) { - if (id == FT_ID_SQB_B && S_st->st_mode) - return (0); + 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(uint8_t id, - char *argv[]) + b_sqb_file_tests(uint8_t id, + char *argv[]) { struct stat st; - int32_t fd; - uint8_t ret; + int32_t fd; - ret = 0; - if ((fd = open(argv[1])) == -1) + if ((fd = open(argv[1], O_RDONLY)) == -1) return (1); + if (id == FT_ID_SQB_E) + { + close(fd); + return (0); + } fstat(fd, &st); - ret = b_file_tests_one(id, &st); close(fd); - return (ret); + if (b_file_tests_one(id, &st) == TRUE) + return (0); + return (1); } |