LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-16-2016, 02:50 PM   #1
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
Query on /etc/profile.d/glib2.sh


Code:
#!/bin/sh
#
# Description:  This script sets the environment variables G_FILENAME_ENCODING
# and G_BROKEN_FILENAMES for the glib-2.0 library.
#
# G_FILENAME_ENCODING
#       This environment variable can be set to a comma-separated list of
#       character set names.  GLib assumes that filenames are encoded in the
#       first character set from that list rather than in UTF-8.  The special
#       token "@locale" can be used to specify the character set for the
#       current locale.
#
# G_BROKEN_FILENAMES
#       If this environment variable is set, GLib assumes that filenames are
#       in the locale encoding rather than in UTF-8.

# If the LANG you have set contains any form of "UTF", we will guess you are
# using a UTF-8 locale.  Hopefully we're correct.
if echo $LANG | grep -iq UTF ; then
  export G_FILENAME_ENCODING="@locale"
fi

# It doesn't hurt to export this since G_FILENAME_ENCODING takes priority
# over G_BROKEN_FILENAMES:
export G_BROKEN_FILENAMES=1
That "rather than utf8" comment suggests that utf8 is the default, in which case it seems like that if statement is actually the wrong way around and needs to be negated: if the default is to assume utf-8 then you'd only need to set it if you're not using a utf8 locale. No?

Or, given that @locale sounds like it ought to work for both utf8 and non-utf8 locales, why not just set it to @locale which should work in both cases.

I freely admit that I know very little about glib. Am I looking at this wrong?


update:

After reading this it sounds like G_FILENAME_ENCODING='@locale' and G_BROKEN_FILENAMES=1 do the same thing?

Last edited by GazL; 11-16-2016 at 04:13 PM.
 
Old 11-17-2016, 08:48 AM   #2
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Original Poster
Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
Actually after doing some reading on the subject, I've come to the conclusion that it's all just broken anyway and the only sensible thing to do is use a utf8 locale, in which case non of these settings are of any use anyway.
 
Old 11-17-2016, 09:26 AM   #3
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,048

Rep: Reputation: Disabled
... And the names of many locales encoded in UTF-8 do not include UTF or utf.

This script lists them:
Code:
#/bin/sh
for i in $(locale -a); do
    if printf $i|grep -viq utf8; then
        if LANG=$i locale -k charmap|grep -q UTF-8; then
            echo $i
        fi
    fi
done

Last edited by Didier Spaier; 11-17-2016 at 09:48 AM.
 
1 members found this post helpful.
Old 11-17-2016, 09:35 AM   #4
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Original Poster
Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
Yep, I'd already changed libglib.sh to be:

Code:
if [ "$(locale -k charmap)" = 'charmap="UTF-8"' ]; then
  export G_FILENAME_ENCODING="UTF-8"
else
  export G_BROKEN_FILENAMES=1
fi
Which would allow individual users who are using non-utf8 locales on a primarily utf8 based system to have the filenames converted for them, but then I realised that as this only effects glib, all the other utilities and non-glib programs would still have to deal with incompatible charsets and that it doesn't really get you anywhere unless you only ever use glib applications.

At which point, I lost heart and went to eat some chocolate to make me feel better.

Last edited by GazL; 11-17-2016 at 09:39 AM.
 
Old 06-13-2021, 08:03 AM   #5
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Original Poster
Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
This thread got mentioned in another thread, so I thought it best to reply here in the original topic to keep things tidy.

Quote:
Originally Posted by NonNonBa View Post
Thank you. But at the end, GazL just improves the way they are written, not enlightening their logic he finds confusing too.
The logic of the above code snippet is essentially correct, however, it's unnecessarily complicated as in practice it'd be no different than just setting G_FILENAME_ENCODING='@locale' regardless of locale used.

G_BROKEN_FILENAMES=1 is just an older and misleadingly named way of specifying G_FILENAME_ENCODING=@locale. They do exactly the same thing.

One only really needs to set this when not using a utf-8 locale as the default behaviour is to run as if G_FILENAME_ENCODING=UTF-8,@locale was specified, which in the case of utf-8 locales is essentially the same as above.

The reason why non-utf8 locales will want to set G_FILENAME_ENCODING=@locale is that it's possible for some non-utf8 sequence to be interpreted as a valid utf8 sequence, so it's safest to prevent that.

P.S. this is really just revisiting some of the things I said in post #1, only I'm a little more confident in my understand of all this 4 years later.

Last edited by GazL; 06-13-2021 at 08:14 AM.
 
1 members found this post helpful.
Old 06-14-2021, 05:33 AM   #6
NonNonBa
Member
 
Registered: Aug 2010
Distribution: Slackware
Posts: 192

Rep: Reputation: Disabled
Quote:
Originally Posted by GazL View Post
The logic of the above code snippet is essentially correct
Not really. As you say, the only case you can get any benefit from G_FILENAME_ENCODING is when you are not using UTF-8. So, if one doesn't want to bloat the environment by always setting it, the only sound code should IMHO rather be:

Code:
if [ ! "$(locale -k charmap)" = 'charmap="UTF-8"' ]; then
  # Let's be conservative, keeping G_BROKEN_FILENAMES.
  export G_FILENAME_ENCODING="@locale" G_BROKEN_FILENAMES=1
fi
Otherwise, your setup is already as glib expects.
 
Old 06-14-2021, 06:02 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Original Poster
Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
You don't need to set both. One or the other will suffice.

As you say, if you care about environment size then you may want to also wrap it in a conditional so that it's not taking up env space when unneeded. Personally I just chmod -x this file.
 
Old 06-14-2021, 12:24 PM   #8
NonNonBa
Member
 
Registered: Aug 2010
Distribution: Slackware
Posts: 192

Rep: Reputation: Disabled
Deleted: didn't make sense; you're right GazL.

Last edited by NonNonBa; 06-14-2021 at 12:26 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Glib-2.22 (Not glib2). cwizardone Slackware 7 04-17-2012 09:53 AM
glib2 issues Cyber Maid Linux - Software 7 05-01-2007 09:37 PM
having problem in installing glib2-2.6.4-1 mohtasham1983 Linux - General 4 09-19-2005 05:51 PM
Upgrading glib2 jrdioko Linux - Software 10 06-04-2005 05:40 PM
upgrade to glib2.3 wilsnyder Linux - Software 1 07-02-2003 05:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration