in src/umocktypes_wcharptr.c [123:165]
int umocktypes_copy_wcharptr(wchar_t** destination, const wchar_t** source)
{
int result;
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_013: [ If source or destination are NULL, umocktypes_copy_wcharptr shall return a non-zero value. ]*/
if ((destination == NULL) || (source == NULL))
{
UMOCK_LOG("umocktypes_copy_wcharptr: Bad arguments: destination = %p, source = %p.",
destination, source);
result = __LINE__;
}
else
{
if (*source == NULL)
{
*destination = NULL;
result = 0;
}
else
{
size_t source_length = wcslen(*source);
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_012: [ The number of bytes allocated shall accommodate the string pointed to by source. ]*/
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_011: [ umocktypes_copy_wcharptr shall allocate a new sequence of chars by using umockalloc_malloc. ]*/
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_015: [ The newly allocated string shall be returned in the destination argument. ]*/
*destination = (wchar_t*)umockalloc_malloc((source_length + 1) * sizeof(wchar_t));
if (*destination == NULL)
{
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_036: [ If allocating the memory for the new string fails, umocktypes_copy_wcharptr shall fail and return a non-zero value. ]*/
UMOCK_LOG("umocktypes_copy_wcharptr: Failed allocating memory for the destination string.");
result = __LINE__;
}
else
{
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_014: [ umocktypes_copy_wcharptr shall copy the string pointed to by source to the newly allocated memory. ]*/
(void)memcpy(*destination, *source, (source_length + 1) * sizeof(wchar_t));
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_016: [ On success umocktypes_copy_wcharptr shall return 0. ]*/
result = 0;
}
}
}
return result;
}