MCPcopy Create free account
hub / github.com/apache/nuttx / my_strndup

Function my_strndup

tools/nxstyle.c:772–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

770 ********************************************************************************/
771
772char *my_strndup(const char *s, size_t size)
773{
774 char *dest = NULL;
775 size_t len;
776
777 len = strnlen(s, size);
778 len = len < size ? len : size;
779 dest = malloc(len + 1);
780
781 if (dest == NULL)
782 {
783 return NULL;
784 }
785
786 memcpy(dest, s, len);
787 dest[len] = '\0';
788 return dest;
789}
790#undef strndup
791# define strndup my_strndup
792#endif

Callers

nothing calls this directly

Calls 3

strnlenFunction · 0.50
mallocFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected