]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
libarchive: Force GNU iconv compatibility on FreeBSD 3056/head
authorMark Johnston <markj@FreeBSD.org>
Wed, 20 May 2026 16:39:40 +0000 (16:39 +0000)
committerMark Johnston <markj@FreeBSD.org>
Wed, 20 May 2026 17:04:17 +0000 (17:04 +0000)
When libarchive is compiled with FreeBSD's native iconv instead of
libiconv, as happens with libarchive in the base system, we need to
configure iconv(3) to handle invalid sequences by returning -1, as
iconv_strncat_in_locale() assumes GNU iconv semantics.

libarchive/archive_string.c

index c6ae8968d54fa6807e7130b27543828365c567d1..4fb96a9fa17895dd397acb30b20acb06b0ad71af 100644 (file)
@@ -1314,7 +1314,17 @@ create_sconv_object(const char *fc, const char *tc,
                        else if (strcmp(fc, "CP932") == 0)
                                sc->cd = iconv_open(tc, "SJIS");
                }
-#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(__FreeBSD__) && !defined(HAVE_LIBICONV)
+               /*
+                * FreeBSD's native iconv() by default returns the number of
+                * invalid characters in the input string, as specified by
+                * POSIX, but iconv_strncat_in_locale() assumes GNU iconv
+                * semantics.
+                */
+               int v = 1;
+
+               (void)iconvctl(sc->cd, ICONV_SET_ILSEQ_INVALID, &v);
+#elif defined(_WIN32) && !defined(__CYGWIN__)
                /*
                 * archive_mstring on Windows directly convert multi-bytes
                 * into archive_wstring in order not to depend on locale