gconvert: match GNU iconv behaviour on FreeBSD

FreeBSD iconv by default handles input characters that are not
representable in the destination character set by emitting a replacement
character such as '?'. While this appears to be the POSIX mandated
behaviour it does not match GNU behaviour and causes the gconvert test
to fail in the `test_one_half` testcase. Fortunately FreeBSD provides a
iconvctl flag to request this behaviour to match GNU iconv.

See https://github.com/freebsd/freebsd-src/commit/7c5b23111c5fd199204
This commit is contained in:
Alex Richardson 2024-01-10 14:12:47 -08:00 committed by Ting-Wei Lan
parent 143cb92c35
commit b65cfc9a99

View File

@ -73,8 +73,17 @@ try_conversion (const char *to_codeset,
if (*cd == (iconv_t)-1 && errno == EINVAL)
return FALSE;
else
return TRUE;
#if defined(__FreeBSD__) && defined(ICONV_SET_ILSEQ_INVALID)
/* On FreeBSD request GNU iconv compatible handling of characters that cannot
* be repesented in the destination character set.
* See https://github.com/freebsd/freebsd-src/commit/7c5b23111c5fd1992
*/
int value = 1;
if (iconvctl (*cd, ICONV_SET_ILSEQ_INVALID, &value) != 0)
return FALSE;
#endif
return TRUE;
}
static gboolean