Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_strdup.c File Reference
+ Include dependency graph for ft_strdup.c:

Go to the source code of this file.

Functions

char * ft_strdup (const char *s)
 Duplicates a C string into newly allocated memory.
 

Function Documentation

◆ ft_strdup()

char * ft_strdup ( const char *  s)

Duplicates a C string into newly allocated memory.

Parameters
sSource string.
Returns
Newly allocated duplicate, or NULL on allocation failure.

Definition at line 21 of file ft_strdup.c.

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}
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

References ft_memcpy(), and ft_strlen().

Referenced by ft_substr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: