-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_ls_4.c
87 lines (79 loc) · 2.69 KB
/
ft_ls_4.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ls_4.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdiouf <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/10/04 00:47:10 by mdiouf #+# #+# */
/* Updated: 2014/10/05 22:48:37 by mdiouf ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void ft_fix_time_str2(char **time)
{
int i;
i = 0;
i = 0;
while ((*time)[i] != ':')
i++;
i = i + 3;
while ((*time)[i] != '\0')
{
((*time)[i] = '\0');
i++;
}
}
void ft_fix_time_str(char **time)
{
int i;
int j;
i = 0;
j = 0;
while ((*time)[i] != ' ')
{
while ((*time)[j + 1] != '\0')
{
(*time)[j] = (*time)[j + 1];
j++;
}
(*time)[j] = (*time)[j + 1];
j = 0;
i++;
}
ft_fix_time_str2(time);
}
void ft_print_rights2(t_dir **vars, int i, t_id *id_vars)
{
ft_putstr(" ");
ft_putnbr((*vars)->files[i].stats.st_nlink);
ft_putstr(" ");
id_vars->pass = getpwuid((*vars)->files[i].stats.st_uid);
id_vars->grp = getgrgid((*vars)->files[i].stats.st_gid);
ft_putstr(id_vars->pass->pw_name);
ft_putstr(" ");
ft_putstr(id_vars->grp->gr_name);
ft_putstr(" ");
ft_putnbr((*vars)->files[i].stats.st_size);
ft_putstr(" ");
ft_putstr(id_vars->time);
ft_putstr(" ");
}
void ft_print_rights(t_dir **vars, int i)
{
t_id id_vars;
id_vars.time = ctime(&((*vars)->files[i].stats.st_mtime));
ft_fix_time_str(&(id_vars.time));
ft_putstr((S_ISDIR((*vars)->files[i].stats.st_mode)) ? "d" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IRUSR) ? "r" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IWUSR) ? "w" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IXUSR) ? "x" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IRGRP) ? "r" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IWGRP) ? "w" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IXGRP) ? "x" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IROTH) ? "r" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IWOTH) ? "w" : "-");
ft_putstr(((*vars)->files[i].stats.st_mode & S_IXOTH) ? "x" : "-");
ft_print_rights2(vars, i, &id_vars);
free((*vars)->files[i].nme);
}