#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Go to the source code of this file.
|
char * | strndup (const char *str, size_t n) |
| Duplicate n bytes of the passed in string str. More...
|
|
◆ strndup()
char* strndup |
( |
const char * |
str, |
|
|
size_t |
n |
|
) |
| |
Duplicate n bytes of the passed in string str.
strndup is similar to
- See also
- strdup, but copies at most n bytes. If str is longer than n, only n bytes are copied, and a terminating null byte ('\0') is added.
- Parameters
-
str | a pointer to a string to duplicate |
n | maximum number of bytes to copy |
- 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 41 of file strndup.c.
49 for(len = 0; len < n && str[len]; len++)
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(), and NULL.