Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_strdup.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strdup.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: raphalme <raphalme@student.42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/12/29 19:01:00 by raphalme #+# #+# */
9/* Updated: 2026/04/14 10:45:22 by raphalme ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "../includes/libft.h"
14
21char *ft_strdup(const char *s)
22{
23 char *dup;
24 size_t len;
25
26 len = ft_strlen(s) + 1;
27 dup = (char *)malloc(len);
28 if (!dup)
29 return (NULL);
30 ft_memcpy(dup, s, len);
31 return (dup);
32}
char * ft_strdup(const char *s)
Duplicates a C string into newly allocated memory.
Definition ft_strdup.c:21
void * ft_memcpy(void *dest, const void *src, size_t n)
Copies bytes from source to destination.
Definition ft_memcpy.c:25
size_t ft_strlen(const char *str)
Returns the length of a null-terminated string.
Definition ft_strlen.c:21