diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-26 01:56:47 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-26 01:56:47 +0200 |
commit | fd708f9e7895f4d094ec0004afa57e4a23bb5252 (patch) | |
tree | d8cc7d487de0a736619c8779ca43a3f5712d8ca3 /src | |
parent | Commit (diff) | |
download | 42-minishell-fd708f9e7895f4d094ec0004afa57e4a23bb5252.tar.gz 42-minishell-fd708f9e7895f4d094ec0004afa57e4a23bb5252.tar.bz2 42-minishell-fd708f9e7895f4d094ec0004afa57e4a23bb5252.tar.xz 42-minishell-fd708f9e7895f4d094ec0004afa57e4a23bb5252.tar.zst 42-minishell-fd708f9e7895f4d094ec0004afa57e4a23bb5252.zip |
Some tests already
Diffstat (limited to '')
-rw-r--r-- | src/b_sqb.c | 2 | ||||
-rw-r--r-- | src/b_sqb_file.c | 43 | ||||
-rw-r--r-- | src/b_sqb_file.h | 2 |
3 files changed, 34 insertions, 13 deletions
diff --git a/src/b_sqb.c b/src/b_sqb.c index 438f692..226d09f 100644 --- a/src/b_sqb.c +++ b/src/b_sqb.c @@ -84,5 +84,5 @@ uint8_t return (1); else if (argc == 2) return (0); - return (b_eval_sqb(argc, args, msh)); + return (b_eval_sqb(args, msh)); } 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); } diff --git a/src/b_sqb_file.h b/src/b_sqb_file.h index d048fd1..0fb7e88 100644 --- a/src/b_sqb_file.h +++ b/src/b_sqb_file.h @@ -15,6 +15,6 @@ #include <stdint.h> -uint8_t b_sqb_file(uint8_t id, char *argv[]); +uint8_t b_sqb_file_tests(uint8_t id, char *argv[]); #endif |