minishell
ft_strjoin.c File Reference
#include "../ft_mem/ft_mem.h"
#include "ft_string.h"
#include <stdlib.h>
Include dependency graph for ft_strjoin.c:

Go to the source code of this file.

Functions

char * ft_strjoin (char const *s1, char const *s2)
 

Function Documentation

◆ ft_strjoin()

char* ft_strjoin ( char const *  s1,
char const *  s2 
)

Definition at line 17 of file ft_strjoin.c.

18 {
19  size_t s1_len;
20  size_t s2_len;
21  char *p_ret;
22 
23  if (s1 == NULL)
24  s1_len = 0;
25  else
26  s1_len = ft_strlen(s1);
27  if (s2 == NULL)
28  s2_len = 0;
29  else
30  s2_len = ft_strlen(s2);
31  p_ret = malloc(s1_len + s2_len + 1);
32  if (p_ret == NULL)
33  return (NULL);
34  ft_memmove(p_ret, s1, s1_len);
35  ft_memmove(p_ret + s1_len, s2, s2_len);
36  p_ret[s1_len + s2_len] = '\0';
37  return (p_ret);
38 }
void * ft_memmove(void *dst, const void *src, size_t n)
Definition: ft_memmove.c:16
size_t ft_strlen(const char *s)
Definition: ft_strlen.c:15
Here is the call graph for this function:
Here is the caller graph for this function: