From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: "Yonggang Luo" <luoyonggang@gmail.com>,
qemu-devel@nongnu.org,
"Daniel P . Berrangé" <berrange@redhat.com>
Cc: "QEMU Trivial" <qemu-trivial@nongnu.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Laurent Vivier" <laurent@vivier.eu>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH v9 2/5] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw
Date: Tue, 13 Oct 2020 10:35:39 +0200 [thread overview]
Message-ID: <dd59aaba-d75e-fab5-5c07-d6b552ff2684@redhat.com> (raw)
In-Reply-To: <20201012234348.1427-3-luoyonggang@gmail.com>
On 10/13/20 1:43 AM, Yonggang Luo wrote:
> msys2/mingw lacks the POSIX-required langinfo.h.
>
> gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
> test.c:4:10: fatal error: langinfo.h: No such file or directory
> 4 | #include <langinfo.h>
> | ^~~~~~~~~~~~
> compilation terminated.
>
> So we using g_get_codeset instead of nl_langinfo(CODESET)
>
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> configure | 5 +----
> ui/curses.c | 10 +++++-----
> 2 files changed, 6 insertions(+), 9 deletions(-)
>
> diff --git a/configure b/configure
> index 1b63488521..71a574f718 100755
> --- a/configure
> +++ b/configure
> @@ -3530,17 +3530,14 @@ if test "$curses" != "no" ; then
> #include <locale.h>
> #include <curses.h>
> #include <wchar.h>
> -#include <langinfo.h>
> int main(void) {
> - const char *codeset;
> wchar_t wch = L'w';
> setlocale(LC_ALL, "");
> resize_term(0, 0);
> addwstr(L"wide chars\n");
> addnwstr(&wch, 1);
> add_wch(WACS_DEGREE);
> - codeset = nl_langinfo(CODESET);
> - return codeset != 0;
> + return 0;
> }
> EOF
> IFS=:
> diff --git a/ui/curses.c b/ui/curses.c
> index a59b23a9cf..12bc682cf9 100644
> --- a/ui/curses.c
> +++ b/ui/curses.c
> @@ -30,7 +30,6 @@
> #endif
> #include <locale.h>
> #include <wchar.h>
> -#include <langinfo.h>
> #include <iconv.h>
>
> #include "qapi/error.h"
> @@ -526,6 +525,7 @@ static void font_setup(void)
> iconv_t nativecharset_to_ucs2;
> iconv_t font_conv;
> int i;
> + g_autofree gchar *local_codeset = g_get_codeset();
>
> /*
> * Control characters are normally non-printable, but VGA does have
> @@ -566,14 +566,14 @@ static void font_setup(void)
> 0x25bc
> };
>
> - ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
> + ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
> if (ucs2_to_nativecharset == (iconv_t) -1) {
> fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n",
> strerror(errno));
> exit(1);
> }
>
> - nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
> + nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);
> if (nativecharset_to_ucs2 == (iconv_t) -1) {
> iconv_close(ucs2_to_nativecharset);
> fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n",
> @@ -581,7 +581,7 @@ static void font_setup(void)
> exit(1);
> }
>
> - font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
> + font_conv = iconv_open(local_codeset, font_charset);
> if (font_conv == (iconv_t) -1) {
> iconv_close(ucs2_to_nativecharset);
> iconv_close(nativecharset_to_ucs2);
> @@ -602,7 +602,7 @@ static void font_setup(void)
> /* DEL */
> convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
>
> - if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
> + if (strcmp(local_codeset, "UTF-8")) {
> /* Non-Unicode capable, use termcap equivalents for those available */
> for (i = 0; i <= 0xFF; i++) {
> wchar_t wch[CCHARW_MAX];
>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
next prev parent reply other threads:[~2020-10-13 8:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-12 23:43 [PATCH v9 0/5] Fixes curses on msys2/mingw Yonggang Luo
2020-10-12 23:43 ` [PATCH v9 1/5] configure: fixes indent of $meson setup Yonggang Luo
2020-10-13 8:35 ` Philippe Mathieu-Daudé
2020-10-12 23:43 ` [PATCH v9 2/5] curses: Fixes compiler error that complain don't have langinfo.h on msys2/mingw Yonggang Luo
2020-10-13 8:35 ` Philippe Mathieu-Daudé [this message]
2020-10-12 23:43 ` [PATCH v9 3/5] curses: Fixes curses compiling errors Yonggang Luo
2020-10-12 23:43 ` [PATCH v9 4/5] win32: Simplify gmtime_r detection not depends on if _POSIX_C_SOURCE are defined on msys2/mingw Yonggang Luo
2020-10-13 8:37 ` Philippe Mathieu-Daudé
2020-10-12 23:43 ` [PATCH v9 5/5] configure: Fixes ncursesw detection under msys2/mingw by convert them to meson Yonggang Luo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dd59aaba-d75e-fab5-5c07-d6b552ff2684@redhat.com \
--to=philmd@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=laurent@vivier.eu \
--cc=luoyonggang@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).