-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.c
70 lines (62 loc) · 1.38 KB
/
time.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
#include <stdlib.h>
#include "my_ls.h"
int time_cmp(time_t t1, time_t t2, char *name, char *next_name)
{
int str_cmp_res;
if (t1 < t2)
return (-1);
if (t1 > t2)
return (1);
str_cmp_res = my_strcmp(name, next_name);
return (str_cmp_res);
}
int push_time_file(t_list_file **pile_file, char *name,
time_t time)
{
t_list_file *new;
t_list_file *tmp;
t_list_file *swap;
tmp = *pile_file;
if ((new = create_elem(name)) == NULL)
return (-1);
while (tmp->next
&& time_cmp(tmp->next->time, time, name, tmp->next->name) > 0)
tmp = tmp->next;
if (time_cmp(tmp->time, time, name, tmp->name) > 0)
{
swap = tmp->next;
tmp->next = new;
new->next = swap;
new->time = time;
return (0);
}
new->next = *pile_file;
new->time = time;
*pile_file = new;
return (0);
}
int push_rtime_file(t_list_file **pile_file, char *name,
time_t time)
{
t_list_file *new;
t_list_file *tmp;
t_list_file *swap;
tmp = *pile_file;
if ((new = create_elem(name)) == NULL)
return (-1);
while (tmp->next
&& time_cmp(tmp->next->time, time, name, tmp->next->name) < 0)
tmp = tmp->next;
if (time_cmp(tmp->time, time, name, tmp->name) < 0)
{
swap = tmp->next;
tmp->next = new;
new->next = swap;
new->time = time;
return (0);
}
new->next = *pile_file;
new->time = time;
*pile_file = new;
return (0);
}