git: bd15d6ef126e - main - libarchive: Force GNU iconv compatibility on FreeBSD
Date: Wed, 27 May 2026 13:17:35 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=bd15d6ef126ee4c0eac931117f6bbbf6f9a3fc72
commit bd15d6ef126ee4c0eac931117f6bbbf6f9a3fc72
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-05-20 16:39:40 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-05-27 13:10:57 +0000
libarchive: Force GNU iconv compatibility on FreeBSD
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.
This corresponds to upstream PR 3056.
PR: 294577
MFC after: 1 week
---
contrib/libarchive/libarchive/archive_string.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/contrib/libarchive/libarchive/archive_string.c b/contrib/libarchive/libarchive/archive_string.c
index c6ae8968d54f..4fb96a9fa178 100644
--- a/contrib/libarchive/libarchive/archive_string.c
+++ b/contrib/libarchive/libarchive/archive_string.c
@@ -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