From d3288e6359744ad0383d08270aea74f4497c974d Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Tue, 28 May 2024 14:51:31 +0200 Subject: wrap: use nl_langinfo to get locale codeset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using more and more complicated constructs comparing locale strings doesn't lead to anywhere. Even with the current two steps long comparison the program is wrong on systems which use "utf8" in their locale names (e.g., my openSUSE/Tumbleweed). It is better to use proper locale functions to get canonical name of the current codeset. Link: https://lists.sr.ht/~rjarry/aerc-devel/%3CD1L7746XIJ3Z.3SN11SOVO175Q@cepl.eu%3E Signed-off-by: Matěj Cepl Acked-by: Robin Jarry --- filters/wrap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'filters') diff --git a/filters/wrap.c b/filters/wrap.c index 59c44522..4ae7c72d 100644 --- a/filters/wrap.c +++ b/filters/wrap.c @@ -1,9 +1,10 @@ /* SPDX-License-Identifier: MIT */ /* Copyright (c) 2023 Robin Jarry */ -#define _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 #include #include +#include #include #include #include @@ -446,7 +447,10 @@ static int set_stdio_encoding(void) } /* aerc will always send UTF-8 text, ensure that we read that properly */ - if (!strstr(locale, "UTF-8") && !strstr(locale, "utf-8")) { + locale_t loc = newlocale(LC_ALL_MASK, locale, NULL); + char *codeset = nl_langinfo_l(CODESET, loc); + freelocale(loc); + if (!strstr(codeset, "UTF-8")) { fprintf(stderr, "error: locale '%s' is not UTF-8\n", locale); return 1; } -- cgit