-
Notifications
You must be signed in to change notification settings - Fork 0
/
putstr.c
77 lines (69 loc) · 1.72 KB
/
putstr.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dmoureu- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/10 18:47:09 by dmoureu- #+# #+# */
/* Updated: 2016/02/11 16:26:57 by dmoureu- ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_ls.h"
void ft_putstrfree(char *str)
{
if (str)
{
ft_putstr(str);
free(str);
str = NULL;
}
}
void ft_putstrnfree(char *str, int n, int s)
{
ft_putstrn(str, n, s);
ft_strdel(&str);
}
char *putstrnright(char *newstr, char *str, int n)
{
int i;
int length;
i = 0;
length = n - ft_strlen(str);
while (i < length)
{
newstr[i] = ' ';
i++;
}
newstr[i] = '\0';
return (ft_strncat(newstr, str, n));
}
void ft_putstrn(char *str, int n, int s)
{
char *newstr;
int i;
i = 0;
newstr = (char *)malloc(sizeof(char) * n + 1);
if (s)
{
newstr = putstrnright(newstr, str, n);
}
else
{
i = ft_strlen(str);
ft_strncpy(newstr, str, n);
while (i < n)
{
newstr[i] = ' ';
i++;
}
newstr[i] = '\0';
}
ft_putstr(newstr);
ft_strdel(&newstr);
}
void ft_putstrpathdir(char *path)
{
ft_putstr(path);
ft_putstr(":\n");
}