34 lines
1.3 KiB
C
34 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_strdup.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/11/07 16:53:59 by rparodi #+# #+# */
|
|
/* Updated: 2024/10/31 18:14:44 by rparodi ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libft.h"
|
|
|
|
/**
|
|
* @brief Duplicates a string.
|
|
*
|
|
* @param s1 The string to duplicate.
|
|
*
|
|
* @return A pointer to the duplicated string,
|
|
* or NULL if memory allocation fails.
|
|
*/
|
|
char *ft_strdup(const char *s)
|
|
{
|
|
size_t len;
|
|
char *to_return;
|
|
|
|
len = ft_strlen(s) + 1;
|
|
to_return = (char *)malloc(sizeof(char) * len);
|
|
if (!to_return)
|
|
return (NULL);
|
|
ft_strlcpy(to_return, s, len);
|
|
return (to_return);
|
|
}
|