Embedded Artistry Framework
Embedded Systems C++ Framework
Functions
strndup.c File Reference
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for strndup.c:

Functions

char * strndup (const char *str, size_t n)
 Duplicate n bytes of the passed in string str. More...
 

Function Documentation

◆ 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
stra pointer to a string to duplicate
nmaximum 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.

References malloc(), memcpy(), n, and NULL.

Referenced by strndup_test().

Here is the caller graph for this function: