From b65cfc9a990e44e47a0a5d56d7ccba1c993782fc Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Wed, 10 Jan 2024 14:12:47 -0800 Subject: [PATCH] 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 --- glib/gconvert.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/glib/gconvert.c b/glib/gconvert.c index 4eaabc278..a2c746f3f 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -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