-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfile_infos.c
More file actions
121 lines (115 loc) · 2.74 KB
/
file_infos.c
File metadata and controls
121 lines (115 loc) · 2.74 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* file_infos.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtacnet <mtacnet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/01 17:43:34 by mtacnet #+# #+# */
/* Updated: 2017/06/17 17:10:15 by mtacnet ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
static void file_types(t_elem *lst)
{
if (S_ISDIR(lst->f_stat.st_mode))
ft_putstr("d");
else if (S_ISFIFO(lst->f_stat.st_mode))
ft_putstr("p");
else if (S_ISREG(lst->f_stat.st_mode))
ft_putstr("-");
else if (S_ISLNK(lst->f_stat.st_mode))
ft_putstr("l");
else if (S_ISSOCK(lst->f_stat.st_mode))
ft_putstr("s");
else if (S_ISBLK(lst->f_stat.st_mode))
ft_putstr("b");
else if (S_ISCHR(lst->f_stat.st_mode))
ft_putstr("c");
else
ft_putstr("-");
}
static void owner_rights(t_elem *lst)
{
if (lst->f_stat.st_mode & S_IRUSR)
ft_putstr("r");
else
ft_putstr("-");
if (lst->f_stat.st_mode & S_IWUSR)
ft_putstr("w");
else
ft_putstr("-");
if (lst->f_stat.st_mode & S_IXUSR)
{
if (lst->f_stat.st_mode & S_ISUID)
ft_putstr("s");
else
ft_putstr("x");
}
else
{
if (lst->f_stat.st_mode & S_ISUID)
ft_putstr("S");
else
ft_putstr("-");
}
}
static void group_rights(t_elem *lst)
{
if (lst->f_stat.st_mode & S_IRGRP)
ft_putstr("r");
else
ft_putstr("-");
if (lst->f_stat.st_mode & S_IWGRP)
ft_putstr("w");
else
ft_putstr("-");
if (lst->f_stat.st_mode & S_IXGRP)
{
if (lst->f_stat.st_mode & S_ISGID)
ft_putstr("s");
else
ft_putstr("x");
}
else
{
if (lst->f_stat.st_mode & S_ISGID)
ft_putstr("S");
else
ft_putstr("-");
}
}
static void other_rights(t_elem *lst)
{
if (lst->f_stat.st_mode & S_IROTH)
ft_putstr("r");
else
ft_putstr("-");
if (lst->f_stat.st_mode & S_IWOTH)
ft_putstr("w");
else
ft_putstr("-");
if (lst->f_stat.st_mode & S_IXOTH)
{
if (lst->f_stat.st_mode & S_ISVTX)
ft_putstr("t");
else
ft_putstr("x");
}
else
{
if (lst->f_stat.st_mode & S_ISVTX)
ft_putstr("T");
else
ft_putstr("-");
}
}
void file_infos(t_elem *lst, t_env *env)
{
file_types(lst);
owner_rights(lst);
group_rights(lst);
other_rights(lst);
ft_putstr(" ");
file_infos2(lst, env);
}