-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_list.c
109 lines (98 loc) · 2.28 KB
/
init_list.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
99
100
101
102
103
104
105
106
107
108
109
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: llacaze <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/12/14 11:10:56 by llacaze #+# #+# */
/* Updated: 2018/01/24 19:35:53 by llacaze ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
t_info *init_info(void)
{
t_info *finfo;
if (!(finfo = (t_info *)malloc(sizeof(t_info) + 5120)))
return (NULL);
finfo->prev = NULL;
finfo->path = NULL;
finfo->uid = NULL;
finfo->gid = NULL;
finfo->date = NULL;
finfo->name = NULL;
finfo->liname = NULL;
finfo->namel = NULL;
finfo->next = NULL;
return (finfo);
}
t_info *refresh_info(t_info *finfo)
{
t_info *tmp;
tmp = finfo;
finfo = finfo->next;
if (!(finfo = (t_info *)malloc(sizeof(t_info) + 5120)))
return (NULL);
finfo->next = NULL;
finfo->path = NULL;
finfo->uid = NULL;
finfo->gid = NULL;
finfo->date = NULL;
finfo->name = NULL;
finfo->liname = NULL;
finfo->namel = NULL;
finfo->prev = tmp;
return (finfo);
}
void free_info(t_info *finfo)
{
t_info *tmp;
finfo = go_begin(finfo);
while (finfo)
{
if (finfo->next)
tmp = finfo->next;
norm_free(finfo);
if (finfo->next)
{
free(finfo);
finfo = tmp;
tmp = NULL;
}
else
break ;
}
free(finfo);
}
void free_info_prev(t_info *finfo)
{
t_info *tmp;
finfo = go_end(finfo);
while (finfo)
{
if (finfo->prev)
tmp = finfo->prev;
norm_free_prev(finfo);
if (finfo->prev)
{
free(finfo);
finfo = tmp;
tmp = NULL;
}
else
break ;
}
free(finfo);
}
t_info *go_begin(t_info *finfo)
{
t_info *tmp;
while (finfo && finfo->prev != NULL)
{
tmp = finfo;
finfo = finfo->prev;
finfo->next = tmp;
tmp = NULL;
}
return (finfo);
}