in src/umocktypes_wcharptr.c [281:323]
int umocktypes_copy_const_wcharptr(const wchar_t** destination, const wchar_t** source)
{
int result;
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_033: [ If source or destination are NULL, umocktypes_copy_const_wcharptr shall return a non-zero value. ]*/
if ((destination == NULL) || (source == NULL))
{
UMOCK_LOG("umocktypes_copy_const_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_029: [ The number of bytes allocated shall accommodate the string pointed to by source. ]*/
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_028: [ umocktypes_copy_const_wcharptr shall allocate a new sequence of chars by using umockalloc_malloc. ]*/
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_031: [ 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_037: [ If allocating the memory for the new string fails, umocktypes_copy_const_wcharptr shall fail and return a non-zero value. ]*/
UMOCK_LOG("umocktypes_copy_const_wcharptr: Cannot allocate memory for destination string.");
result = __LINE__;
}
else
{
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_030: [ umocktypes_copy_const_wcharptr shall copy the string pointed to by source to the newly allocated memory. ]*/
(void)memcpy((void*)*destination, *source, (source_length + 1) * sizeof(wchar_t));
/* Codes_SRS_UMOCKTYPES_WCHARPTR_01_032: [ On success umocktypes_copy_const_wcharptr shall return 0. ]*/
result = 0;
}
}
}
return result;
}