libft
Loading...
Searching...
No Matches
ft_strlcpy.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strlcpy.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tspoof <tspoof@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2022/10/27 10:36:33 by tspoof #+# #+# */
9/* Updated: 2022/11/03 15:10:39 by tspoof ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "libft.h"
14
15size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
16{
17 size_t n;
18
19 n = ft_strlen(src);
20 if (dstsize > 0)
21 {
22 if (n < dstsize)
23 ft_memcpy(dst, src, n + 1);
24 else
25 {
26 ft_memcpy(dst, src, dstsize - 1);
27 dst[dstsize - 1] = '\0';
28 }
29 }
30 return (n);
31}
size_t ft_strlcpy(char *dst, const char *src, size_t dstsize)
Copies string to destination.
Definition ft_strlcpy.c:15
void * ft_memcpy(void *dst, const void *src, size_t n)
Copies memory to destination.
Definition ft_memcpy.c:15
size_t ft_strlen(const char *s)
Length of the string.
Definition ft_strlen.c:15