-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuts.c
56 lines (51 loc) · 1.15 KB
/
cuts.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
/*
** cuts.c for my_ls in /home/gwitrand/Projects/Mini-project/PSU_2016_my_ls
**
** Made by Witrand Gaspard
** Login <[email protected]>
**
** Started on Sun Dec 4 22:40:39 2016 Witrand Gaspard
** Last update Sun Dec 4 22:40:39 2016 Witrand Gaspard
*/
#include "my_ls.h"
char *cut_time(time_t *time_arg)
{
static int time_actual;
int i;
int nb_two_dots;
char *times;
static time_t *test;
i = 0;
nb_two_dots = 0;
if (time_actual == 0)
time_actual = time(test);
if ((((unsigned int)*time_arg + 15778463) <= time_actual)
|| (time_actual + 3600) <= *time_arg)
return (print_year(time_arg));
times = ctime(time_arg);
while (times[i] != ' ')
i = i + 1;
times = times + i + 1;
while (times[i] && nb_two_dots < 2)
{
if (times[i] == ':' && nb_two_dots == 1)
times[i] = '\0';
if (times[i++] == ':')
nb_two_dots = nb_two_dots + 1;
}
return (times);
}
char *cut_name(char *name)
{
int i;
i = 0;
if (name[1] == 0)
return (name);
while (name[i])
i = i + 1;
while (name[i] != '/' && i > 0)
i = i - 1;
if (i != 0 && name[i + 1] != '\0')
return (name + i + 1);
return (name);
}