Wireshark mailing list archives

Re: Build fails on SuSE 11.3, print_stream.c:151: error: implicit declaration of function 'g_get_codeset'


From: Guy Harris <guy () alum mit edu>
Date: Fri, 13 May 2016 08:00:28 -0700

On May 13, 2016, at 3:15 AM, Anders Broman <anders.broman () ericsson com> wrote:

The reporter says:
glib2-lang-2.22.5-0.2.23
glib2-2.22.5-0.2.23

And, annoyingly, GLib 2.22.5 *defines* g_get_codeset() in glib/gutils.c, but doesn't bother *declaring* it in 
glib/gutils.h, unlike other routines such as, for example, g_atexit(), which *is* declared in glib/gutils.h.

Equally annoyingly, they don't mention g_get_codeset() anywhere in the NEWS file.

However:

        g_get_codeset() appears to be a thin wrapper around g_get_charset();

        g_get_charset() is documented as "[obtaining] the character set for the current locale" and g_get_codeset is 
documented as "[getting] the character set for the current locale", which sounds as if g_get_codeset() is no *better* 
at getting the character set for the current locale;

        g_get_codeset() merely discards the Boolean return value of g_get_charset(), which is TRUE if it's UTF-8 and 
FALSE otherwise, and does a g_strdup() of the string provided by g_get_charset();

        g_get_charset() *is* declared in glib/gunicode.h, which is included in glib/glib.h;

so perhaps we should just use g_get_charset():

diff --git a/epan/print_stream.c b/epan/print_stream.c
index 740773a..4bb427d 100644
--- a/epan/print_stream.c
+++ b/epan/print_stream.c
@@ -146,14 +146,14 @@ print_line_text(print_stream_t *self, int indent, const char *line)
 #ifndef _WIN32
         /* Is there a more reliable way to do this? */
         if (!tty_codeset) {
-            gchar *upper_codeset;
+            gchar *charset;
+            gboolean is_utf8;
 
-            tty_codeset = g_get_codeset();
-            upper_codeset = g_ascii_strup(tty_codeset, -1);
-            if (!strstr(upper_codeset, "UTF-8") && !strstr(upper_codeset, "UTF8")) {
+            is_utf8 = g_get_charset(&charset);
+            tty_codeset = g_strdup(charset);
+            if (!is_utf8) {
                 to_codeset = tty_codeset;
             }
-            g_free(upper_codeset);
         }
 #endif

or something such as that.

Now, GLib doesn't check for "UTF8", just "UTF-8", and assumes that the string doesn't have "utf-8" (or "UtF-8" or 
"uTF-8" or...), so maybe it's not as reliable as is necessary; if we need to worry about something other than "UTF-8" 
being included in the string, then we'd leave our string-checking in place and ignore the return value of 
g_get_charset().

I'm not sure whether the g_strdup() is necessary; if the string provided by g_get_charset() never gets changed or 
freed, it's not necessary.
 

___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev () wireshark org>
Archives:    https://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request () wireshark org?subject=unsubscribe


Current thread: