-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_path.c
More file actions
94 lines (83 loc) · 2.08 KB
/
ft_path.c
File metadata and controls
94 lines (83 loc) · 2.08 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_path.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ichemenc <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/19 14:32:24 by ichemenc #+# #+# */
/* Updated: 2017/03/20 20:53:37 by ichemenc ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/includes/libft.h"
#include "ft_ls.h"
char *ft_strjoin_ls(char const *s1, char const *s2)
{
char *ret;
char *temp_ret;
int i;
int j;
if (s1 == NULL || s2 == NULL)
return (NULL);
i = ft_strlen((char*)s1);
j = ft_strlen((char*)s2);
ret = (char *)malloc(sizeof(char) * (i + j) + 2);
if (ret == NULL)
return (NULL);
temp_ret = ret;
while (*s1 != '\0')
*temp_ret++ = *s1++;
*temp_ret = '/';
temp_ret++;
while (*s2 != '\0')
*temp_ret++ = *s2++;
*temp_ret = '\0';
return (ret);
}
int ndigits(int n)
{
int d;
d = 1;
while (n /= 10)
d++;
return (d);
}
void ft_printlink(int nbr)
{
int i;
int f;
i = ndigits(nbr);
f = g_size1;
while (f > i)
{
ft_putstr(" ");
f--;
}
ft_putnbr(nbr);
}
void ft_print_pw_name(char *str)
{
int i;
int f;
i = ft_strlen(str);
f = g_size2;
while (f > i)
{
ft_putstr(" ");
f--;
}
ft_putstr(str);
}
void ft_open_dir_error(t_ls **elem)
{
t_ls *ptr;
ptr = *elem;
if (ptr->next != NULL || ptr->prev != NULL)
{
ft_putstr_fd(ft_strjoin("\n", ft_strjoin("./", ptr->name)), 2);
ft_putstr_fd(":\n", 2);
}
ft_putstr_fd("ls: ", 2);
ft_putstr_fd((ft_strjoin(ptr->name, ": ")), 2);
ft_putstr_fd(ft_strjoin(strerror(errno), "\n"), 2);
}