-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmore_print_file.c
98 lines (89 loc) · 2.63 KB
/
more_print_file.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
94
95
96
97
98
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* more_print_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ihermell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/25 11:33:16 by ihermell #+# #+# */
/* Updated: 2014/12/03 10:37:25 by ihermell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void print_file_type(t_data *file)
{
if (file->type == T_DIR)
ft_putchar('d');
else if (file->type == T_FILE)
ft_putchar('-');
else if (file->type == T_LNK)
ft_putchar('l');
else if (file->type == T_FIFO)
ft_putchar('p');
else if (file->type == T_SOCK)
ft_putchar('s');
else if (file->type == T_BLK)
ft_putchar('b');
else if (file->type == T_CHR)
ft_putchar('c');
}
void print_device(t_data *file, int *width)
{
int major_len;
int major_width;
major_len = ft_intlen(major(file->stat->st_rdev));
major_width = width[P_MAJOR];
ft_putchar(' ');
while (major_width-- - major_len >= 0)
ft_putchar(' ');
ft_putnbr(major(file->stat->st_rdev));
ft_putchar(',');
print_nbr_col(minor(file->stat->st_rdev), width[P_MINOR]);
}
void print_pointed_dir(t_data *file)
{
int res;
char name[256];
res = readlink(file->path, name, 256);
name[res] = '\0';
ft_putstr(" -> ");
ft_putstr(name);
}
void print_date(time_t timestamp)
{
char *date;
time_t now;
now = time(NULL);
date = ctime(×tamp);
if (g_flags[FLAG_TT])
{
date[24] = '\0';
ft_putstr(date + 4);
ft_putchar(' ');
return ;
}
write(1, date + 4, 7);
if (timestamp > now || now - timestamp > 15778463)
{
ft_putchar(' ');
write(1, date + 20, 4);
}
else
write(1, date + 11, 5);
ft_putchar(' ');
}
void print_user_group(t_data *file, int *width)
{
if (!g_flags[FLAG_G])
{
if (getpwuid(file->stat->st_uid))
print_char_col(getpwuid(file->stat->st_uid)->pw_name, width[USER]);
else
print_char_col(ft_itoa(file->stat->st_uid), width[USER]);
ft_putchar(' ');
}
if (getgrgid(file->stat->st_gid))
print_char_col(getgrgid(file->stat->st_gid)->gr_name, width[GRP]);
else
print_char_col(ft_itoa(file->stat->st_gid), width[GRP]);
}