-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_strnjoin.c
37 lines (34 loc) · 1.28 KB
/
ft_strnjoin.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ewilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/17 15:02:40 by ewilliam #+# #+# */
/* Updated: 2017/01/17 15:03:00 by ewilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnjoin(char **old, const char *new, size_t len)
{
char *tmp;
size_t old_len;
size_t total_len;
old_len = *old == NULL
? 0
: ft_strlen(*old);
total_len = *old == NULL
? len
: len + old_len;
tmp = ft_strnew(total_len);
if (*old == NULL)
ft_memmove(tmp, new, len);
else
{
ft_memmove(ft_stpcpy(tmp, *old), new, len);
ft_strdel(&(*old));
}
*old = tmp;
return (*old);
}