-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strjoin.c
executable file
·43 lines (38 loc) · 1.49 KB
/
ft_strjoin.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/19 07:25:17 by akharrou #+# #+# */
/* Updated: 2019/05/02 15:18:57 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
#include "../Includes/string_42.h"
#include "../Includes/stdlib_42.h"
char *ft_strjoin(char const *s1, char const *s2)
{
char *new_str;
if (s1 || s2)
{
if (!s2)
return (ft_strdup((char *)s1));
if (!s1)
return (ft_strdup((char *)s2));
if (!(new_str = ft_strnew(ft_strlen(s1) + ft_strlen(s2) + 1)))
return (NULL);
return (ft_strcat(ft_strcat(new_str, s1), s2));
}
return (NULL);
}
char *ft_strjoinfre(char const *s1, char const *s2, int free_s1, int free_s2)
{
char *new_str;
new_str = ft_strjoin(s1, s2);
if (free_s1 && s1)
free((void *)s1);
if (free_s2 && s2)
free((void *)s2);
return (new_str);
}