g_get_charset() always returns ANSI_X3.4-1968



Folks,
	So, I've been trying to use a locale other than POSIX C in
working with GTK+/GLib 2.  Unfortnately I've discovered that gutf8
doesn't believe in any user charset other than ANSI_X3.4-1968.  The
simple test program:

#include <stdio.h>
#include <glib.h>


gint main(gint argc, gchar *argv[])
{
    gchar *res;
    const gchar *charset;
    GError *error = NULL; 

    g_get_charset(&charset);
    g_print("Charset is %s\n", charset);
    if (argc > 1)
    {
        res = g_locale_to_utf8(argv[1], -1, NULL, NULL, &error);
        if (res)
            g_print("%s", res);
        else if (error) 
            g_print("%s\n", error->message);
    }
    return(0);
}

*always* prints "Charset is ANSI_X3.4-1968".  If there are non-ASCII
characters in the input, it errors obviously.
	Looking through the g_get_charset() code
(g_utf8_get_charset_internal() to _g_locale_get_charset()), it appears
that _g_locale_get_charset() expects to read $(libdir)/charset.alias.
However, this file is never installed, and in fact config.charset
creates an almost empty file.  The config.charset text seems to imply
that linux needs not the charset.alias file, because glibc gets it
right, but since _g_locale_get_charset() never asks glibc, the answer is
never found.  Instead, _g_locale_get_charset() fails to open
charset.alias and instead returns the default fallback, which is ASCII.
	This is a big problem for many reasons.
g_locale_{to,from}_utf8() rely on g_get_charset() to return a valid
answer.  This is pretty essential to convenient character set work.
	In my case, I had set my locale to en_US.UTF-8 in an attempt to
run an all-UTF-8 environment.  Imagine my surprise when GTK+/GLib 2
refused to let me.
	I note that hte first place g_utf8_get_charset_internal() looks
is to the environment variable "CHARSET".  I've never seen this variable
set in any environment I've worked with, but if this is supposed to be
the "correct" solution, we should have the gdm maintainer set this value
along with LANG upon login.

Joel

-- 

Life's Little Instruction Book #267

	"Lie on your back and look at the stars."

			http://www.jlbec.org/
			jlbec evilplan org



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]