u32 gf_utf8_wcstombs(char* dest, size_t len, const unsigned short** srcp)
{
	if (!srcp || !*srcp)
		return 0;
	else {
		const UTF16** sourceStart = srcp;
		const UTF16* sourceEnd = *srcp + gf_utf8_wcslen(*srcp);
		UTF8* targetStart = (UTF8*) dest;
		UTF8* targetEnd = (UTF8*) dest + len;
		ConversionFlags flags = strictConversion;

		ConversionResult res = ConvertUTF16toUTF8(sourceStart, sourceEnd, &targetStart, targetEnd, flags);
		if (res != conversionOK) return GF_UTF8_FAIL;
		*targetStart = 0;
		*srcp=NULL;
		return (u32) strlen(dest);
	}
}
u32 gf_utf8_wcstombs(char* dest, size_t len, const unsigned short** srcp)
{
	if (!srcp || !*srcp)
		return 0;
	else {
		const UTF16** sourceStart = srcp;
		const UTF16* sourceEnd = *srcp + gf_utf8_wcslen(*srcp);
		UTF8* targetStart = (UTF8*) dest;
		UTF8* targetEnd = (UTF8*) dest + len;
		ConversionFlags flags = strictConversion;

		ConversionResult res = ConvertUTF16toUTF8(sourceStart, sourceEnd, &targetStart, targetEnd, flags);
		if (res != conversionOK) return GF_UTF8_FAIL;
		*targetStart = 0;
		*srcp=NULL;
		return (u32) strlen(dest);
	}
}