-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.c
84 lines (76 loc) · 2.22 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ihermell <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/11/24 00:06:24 by ihermell #+# #+# */
/* Updated: 2014/12/04 17:30:48 by ihermell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
t_data *lst_new_data(char *d_name, char *path)
{
int result;
t_data *new;
t_stat temp;
new = (t_data*)malloc(sizeof(t_data));
new->stat = (t_stat*)malloc(sizeof(t_stat));
result = lstat(path, new->stat);
if (g_settings[S_CALL] == 0 && g_flags[FLAG_L] == 0 && result == 0
&& lst_data_type(new->stat) == T_LNK
&& stat(path, &temp) == 0 && lst_data_type(&temp) == T_DIR)
result = stat(path, new->stat);
new->error = NULL;
if (result == -1)
{
new->type = T_ERROR;
new->error = strerror(errno);
}
else
new->type = lst_data_type(new->stat);
new->d_name = d_name;
new->path = path;
new->prev = NULL;
new->next = NULL;
return (new);
}
void lst_push_data(t_data *data, t_data **data_lst)
{
if (data_lst)
{
data->prev = NULL;
data->next = *data_lst;
if (*data_lst)
(*data_lst)->prev = data;
*data_lst = data;
}
}
void lst_insert_before(t_data *insert, t_data *here)
{
insert->next = here;
insert->prev = here->prev;
here->prev = insert;
if (insert->prev)
insert->prev->next = insert;
}
void lst_insert_after(t_data *insert, t_data *here)
{
insert->next = here->next;
insert->prev = here;
here->next = insert;
if (insert->next)
insert->next->prev = insert;
}
int lst_count(t_data *data_lst)
{
int sum;
sum = 0;
while (data_lst)
{
sum++;
data_lst = data_lst->next;
}
return (sum);
}