source/AccessorySDK/Support/utfconv.c
int
	latin1_to_utf8_copy( 
		const void *	inLatin1Ptr, 
		size_t			inLatin1Len, 
		void *			outUTF8Ptr, 
		size_t *		outUTF8Len, 
		uint16_t		inAltSlash, 
		int				inFlags )
{
	int					err;
	const uint8_t *		src;
	const uint8_t *		end;
	size_t				utf16len;
	uint16_t *			utf16buf;
	uint16_t *			utf16ptr;
	
	// Convert Windows Latin-1 (ANSI Codepage 1252) to UTF-16 in a temporary buffer.
	
	utf16len = inLatin1Len * 2;
	utf16buf = (uint16_t *) utfmalloc( utf16len + 2 );
	if( !utf16buf ) { err = ENOMEM; goto exit; };
	static_analyzer_mem_zeroed( utf16buf, utf16len ); // Remove when <radar:15309659> is fixed.
	utf16ptr = utf16buf;
	
	src = (const uint8_t *) inLatin1Ptr;
	end = src + inLatin1Len;
	while( src != end )
	{
		*utf16ptr++ = kWindowsLatin1ToUTF16[ *src++ ];
	}
	
	// Convert UTF-16 to UTF-8 into a new buffer.
	
	err = utf8_encodestr_copy( utf16buf, utf16len, outUTF8Ptr, outUTF8Len, inAltSlash, inFlags );
	
exit:
	if( utf16buf ) utffree( utf16buf );
	return( err );
}
/*
 * latin1_to_utf8 - Converts Windows Latin-1 to UTF-8 into a malloc'd buffer.
 *
 * NOTES:
 *    On success, the caller must use utffree to free the UTF-8 buffer when no longer needed.
 *    Otherwise, the same notes as utf8_encodestr.
 *
 * FLAGS:
 *    Same flags as utf8_encodestr.
 *
 * ERRORS:
 *    Same errors as utf8_encodestr.
 */
Converts Windows Latin-1 to UTF-8 into a malloc'd buffer.
NOTES:
On success, the caller must use utffree to free the UTF-8 buffer when no longer needed.
Otherwise, the same notes as utf8_encodestr.

Same flags as utf8_encodestr.

Same errors as utf8_encodestr.
Converts Windows Latin - 1 to UTF - 8 into a malloc ' d buffer . NOTES : On success the caller must use utffree to free the UTF - 8 buffer when no longer needed . Otherwise the same notes as utf8_encodestr . Same flags as utf8_encodestr . Same errors as utf8_encodestr .
int
	latin1_to_utf8_copy( 
		const void *	inLatin1Ptr, 
		size_t			inLatin1Len, 
		void *			outUTF8Ptr, 
		size_t *		outUTF8Len, 
		uint16_t		inAltSlash, 
		int				inFlags )
{
	int					err;
	const uint8_t *		src;
	const uint8_t *		end;
	size_t				utf16len;
	uint16_t *			utf16buf;
	uint16_t *			utf16ptr;
	utf16len = inLatin1Len * 2;
	utf16buf = (uint16_t *) utfmalloc( utf16len + 2 );
	if( !utf16buf ) { err = ENOMEM; goto exit; };
	static_analyzer_mem_zeroed( utf16buf, utf16len ); 
	utf16ptr = utf16buf;
	src = (const uint8_t *) inLatin1Ptr;
	end = src + inLatin1Len;
	while( src != end )
	{
		*utf16ptr++ = kWindowsLatin1ToUTF16[ *src++ ];
	}
	err = utf8_encodestr_copy( utf16buf, utf16len, outUTF8Ptr, outUTF8Len, inAltSlash, inFlags );
exit:
	if( utf16buf ) utffree( utf16buf );
	return( err );
}
int latin1_to_utf8_copy ( const void * inLatin1Ptr , size_t inLatin1Len , void * outUTF8Ptr , size_t * outUTF8Len , uint16_t inAltSlash , int inFlags ) { int err ; const uint8_t * src ; const uint8_t * end ; size_t utf16len ; uint16_t * utf16buf ; uint16_t * utf16ptr ; utf16len = inLatin1Len * 2 ; utf16buf = ( uint16_t * ) utfmalloc ( utf16len + 2 ) ; if ( ! utf16buf ) { err = ENOMEM ; goto exit ; } ; static_analyzer_mem_zeroed ( utf16buf , utf16len ) ; utf16ptr = utf16buf ; src = ( const uint8_t * ) inLatin1Ptr ; end = src + inLatin1Len ; while ( src != end ) { * utf16ptr ++ = kWindowsLatin1ToUTF16 [ * src ++ ] ; } err = utf8_encodestr_copy ( utf16buf , utf16len , outUTF8Ptr , outUTF8Len , inAltSlash , inFlags ) ; exit : if ( utf16buf ) utffree ( utf16buf ) ; return ( err ) ; }
latin1_to_utf8 - Converts Windows Latin-1 to UTF-8 into a malloc'd buffer.
latin1_to_utf8 - Converts Windows Latin - 1 to UTF - 8 into a malloc ' d buffer .
// Convert Windows Latin-1 (ANSI Codepage 1252) to UTF-16 in a temporary buffer. // Remove when <radar:15309659> is fixed. // Convert UTF-16 to UTF-8 into a new buffer.