tgrekov-libft
HIVE libft Oct 2023
Loading...
Searching...
No Matches
ft_strdup.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strdup.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2023/10/25 15:03:22 by tgrekov #+# #+# */
9/* Updated: 2023/11/09 20:12:24 by tgrekov ### ########.fr */
10/* */
11/* ************************************************************************** */
12
20#include "libft.h"
21
28char *ft_strdup(const char *s1)
29{
30 size_t size;
31 char *s2;
32
33 size = ft_strlen(s1);
34 s2 = malloc(size + 1);
35 if (!s2)
36 return (0);
37 return (ft_memcpy(s2, s1, size + 1));
38}
void * ft_memcpy(void *dst, const void *src, size_t n)
Copies n bytes from byte string src to byte string dst.
Definition ft_memcpy.c:36
char * ft_strdup(const char *s1)
Allocates memory for, copies to, and returns a duplicate of s1.
Definition ft_strdup.c:28
size_t ft_strlen(const char *str)
Get length of str.
Definition ft_strlen.c:28