-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint.c
More file actions
99 lines (91 loc) · 2.92 KB
/
Copy pathprint.c
File metadata and controls
99 lines (91 loc) · 2.92 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asarandi <asarandi@student.42.us.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/03 18:32:06 by asarandi #+# #+# */
/* Updated: 2017/12/04 17:13:29 by asarandi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void print_basic(t_file *list)
{
while (list)
{
ft_printf(1, "%s", list->name);
print_entry_symbol(list->st.st_mode);
ft_printf(1, "\n");
list = list->next;
}
}
void print_time(t_file *list)
{
struct timespec ts;
if (g_opt.time == 1)
ts = list->st.st_atimespec;
else if (g_opt.time == 3)
ts = list->st.st_ctimespec;
else if (g_opt.time == 2)
ts = list->st.st_birthtimespec;
else
ts = list->st.st_mtimespec;
if (g_opt.fulltime == 1)
ft_printf(1, "%.20s ", ctime(&ts.tv_sec) + 4);
else
ft_printf(1, "%.12s ", make_time_string(ts));
}
void print_size(t_file *list)
{
if (g_width.has_cb)
{
if ((S_ISCHR(list->st.st_mode)) || (S_ISBLK(list->st.st_mode)))
{
ft_printf(1, "%3d, ", major(list->st.st_rdev));
if ((minor(list->st.st_rdev) > 255)
|| (minor(list->st.st_rdev) < 0))
ft_printf(1, "0x%08x ", minor(list->st.st_rdev));
else
ft_printf(1, "%3d ", minor(list->st.st_rdev));
}
else
ft_printf(1, "%*s%*llu ", 8 - g_width.size,
"", g_width.size, list->st.st_size);
}
else
ft_printf(1, "%*llu ", g_width.size, list->st.st_size);
}
void print_owner_group(t_file *list)
{
struct passwd *pwd;
struct group *grp;
pwd = getpwuid(list->st.st_uid);
if ((pwd != NULL) && (g_opt.hide_owner == 0))
ft_printf(1, "%-*s ", g_width.owner, pwd->pw_name);
grp = getgrgid(list->st.st_gid);
if ((grp != NULL) && (g_opt.hide_group == 0))
ft_printf(1, "%-*s ", g_width.group, grp->gr_name);
if ((g_opt.hide_owner == 1) && (g_opt.hide_group == 1))
ft_printf(1, " ");
}
void print_long(char *path, t_file *list)
{
get_directory_widths(list);
if (*path)
ft_printf(1, "total %llu\n", g_width.blocks);
while (list != NULL)
{
print_file_mode(list->st.st_mode);
print_extended_attributes(path, list);
ft_printf(1, " %*u ", g_width.links, list->st.st_nlink);
(void)print_owner_group(list);
(void)print_size(list);
(void)print_time(list);
ft_printf(1, "%s", list->name);
print_entry_symbol(list->st.st_mode);
(void)print_symlink(list, path);
ft_printf(1, "\n");
list = list->next;
}
}