-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_lst.c
93 lines (82 loc) · 2.46 KB
/
data_lst.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
88
89
90
91
92
93
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* data_lst.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ihermell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/24 03:22:11 by ihermell #+# #+# */
/* Updated: 2014/12/04 15:17:06 by ihermell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void print_block_size(t_data *data_lst)
{
quad_t sum;
sum = 0;
while (data_lst)
{
sum += data_lst->stat->st_blocks;
data_lst = data_lst->next;
}
ft_putstr("total ");
ft_putlnbr(sum);
ft_putchar('\n');
}
int *lst_max_properties_length(t_data *data_lst)
{
int *max;
int len;
max = (int*)malloc(sizeof(int) * 7);
bzero(max, sizeof(int) * 7);
while (data_lst)
{
if (data_lst->type == T_CHR || data_lst->type == T_BLK)
max[HAS_DEVICE] = 1;
if ((len = ft_intlen(data_lst->stat->st_nlink)) > max[NLINK])
max[NLINK] = len;
if ((len = get_user_len(data_lst->stat)) > max[USER])
max[USER] = len;
if ((len = get_gr_len(data_lst->stat)) > max[GRP])
max[GRP] = len;
if ((len = ft_intlen(data_lst->stat->st_size)) > max[FILE_SIZE])
max[FILE_SIZE] = len;
if ((len = ft_intlen(major(data_lst->stat->st_rdev))) > max[P_MAJOR])
max[P_MAJOR] = len;
if ((len = ft_intlen(minor(data_lst->stat->st_rdev))) > max[P_MINOR])
max[P_MINOR] = len;
data_lst = data_lst->next;
}
return (max);
}
int get_user_len(t_stat *stat)
{
int len;
if (getpwuid(stat->st_uid))
len = ft_strlen(getpwuid(stat->st_uid)->pw_name);
else
len = ft_intlen(stat->st_uid);
return (len);
}
int get_gr_len(t_stat *stat)
{
int len;
if (getgrgid(stat->st_gid))
len = ft_strlen(getgrgid(stat->st_gid)->gr_name);
else
len = ft_intlen(stat->st_gid);
return (len);
}
int get_name_len(t_data *lst)
{
int max;
int len;
max = 0;
while (lst)
{
if ((len = ft_strlen(lst->d_name)) > max)
max = len;
lst = lst->next;
}
return (max);
}