libft
ft_strlcpy.c
Go to the documentation of this file.
1 /* ************************************************************************** */
3 /* */
4 /* ::: :::::::: */
5 /* ft_strlcpy.c :+: :+: :+: */
6 /* +:+ +:+ +:+ */
7 /* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8 /* +#+#+#+#+#+ +#+ */
9 /* Created: 2019/10/02 02:48:10 by unite #+# #+# */
10 /* Updated: 2020/07/16 02:44:20 by unite ### ########.fr */
11 /* */
12 /* ************************************************************************** */
13 
14 #include "libft.h"
15 
20 size_t ft_strlcpy(char *dst, const char *src, size_t maxlen)
21 {
22  size_t srclen;
23 
24  srclen = ft_strlen(src);
25  if (srclen + 1 < maxlen)
26  {
27  ft_memcpy(dst, src, srclen + 1);
28  }
29  else if (maxlen != 0)
30  {
31  ft_memcpy(dst, src, maxlen - 1);
32  dst[maxlen - 1] = '\0';
33  }
34  return (srclen);
35 }
ft_strlcpy
size_t ft_strlcpy(char *dst, const char *src, size_t maxlen)
Replicates behaviour of strlcpy from libc.
Definition: ft_strlcpy.c:20
ft_strlen
size_t ft_strlen(const char *s)
Replicates behaviour of strlen from libc.
Definition: ft_strlen.c:20
ft_memcpy
void * ft_memcpy(void *dst, const void *src, size_t n)
Replicates behaviour of memcpy from libc.
Definition: ft_memcpy.c:20
libft.h