blob: c371d508598b54e959ce0d5367e66e764647afae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* b_sqb_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <sys/stat.h>
#include <libft.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include "d_define.h"
static t_bool
b_file_tests_one(uint8_t id,
const char path[],
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);
else if (id == FT_ID_SQB_R && access(path, R_OK) == 0)
return (TRUE);
else if (id == FT_ID_SQB_S && st->st_size != 0)
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);
}
close(fd);
if (id == FT_ID_SQB_H || id == FT_ID_SQB_L_MAJ)
lstat(argv[1], &st);
else
stat(argv[1], &st);
if (b_file_tests_one(id, argv[1], &st) == TRUE)
return (0);
return (1);
}
|