#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
|
| char * | strdup (const char *str) |
| | Duplicate the passed in string str. More...
|
| |
◆ strdup()
| char* strdup |
( |
const char * |
str | ) |
|
Duplicate the passed in string str.
Returns a pointer to a new string which is a duplicate of the string str. Memory for the new string is obtained with malloc(3), and can be freed with free(3).
- Parameters
-
| str | a pointer to a string to duplicate |
- Returns
- a pointer to the duplicated string on success. NULL if insufficient memory was available, with errno set to indicate cause of error.
Definition at line 42 of file strdup.c.
48 size_t len =
strlen(str) + 1;
size_t strlen(const char *str)
Returns the length of the given null-terminated byte string.
void * malloc(size_t size)
Allocates size bytes of uninitialized storage.
void * memcpy(void *__restrict dest, const void *__restrict src, size_t n)
Copies n characters from the object pointed to by src to the object pointed to by dest.
References malloc(), memcpy(), NULL, and strlen().