git: libc: Fix (and improve) nl_langinfo (CODESET)

John Marino marino at crater.dragonflybsd.org
Sun Nov 1 02:48:39 PST 2015


commit aafe6cccf26a84b0d7728fef5d976c0d6c09e3c6
Author: John Marino <draco at marino.st>
Date:   Sun Nov 1 11:42:10 2015 +0100

    libc: Fix (and improve) nl_langinfo (CODESET)
    
    The output of "locale charmap" is identical to the result of
    nl_langinfo (CODESET) for any given locale.  The logic for returning the
    codeset was very simplistic.  It just returned portion of the locale name
    after the period (e.g. en_FR.ISO8859-1 returned "ISO8859-1").
    
    When softlinks were added to locales, this broke.  e.g.:
       en_US returned ""
       en_FR.UTF8 returned "UTF8"
       en_FR.UTF-8 returned "UTF-8"
       zh_Hant_HK.Big5HKSCS returned "Big5HKSCS"
       zh_Hant_TW.Big5 returned "Big5"
       es_ES at euro returned ""
    
    In order to fix this properly, the named locale cannot be used to
    determine the encoding.  This information was almost available in the
    rune data.  Unfortunately, all the single byte encodings were listed
    as "NONE" encoding.
    
    So I adjusted localedef tool to provide more information about the
    encoding.  For example, instead of "NONE", the LC_CTYPE used by
    fr_FR.ISO8859-15 is now encoded as "NONE:ISO8859-15".  The locale
    handlers now check if the first four characters of the encoding is
    "NONE" and if so, treats it as a single-byte encoding.
    
    The nl_langinfo handling of CODESET was adjusting accordingly.  Now the
    following is returned:
       en_US returns "ISO8859-1"
       fr_FR.UTF8 returns "UTF-8"
       fr_FR.UTF-8 returns "UTF-8"
       zh_Hant_HK.Big5HKSCS returns "Big5"
       zh_Hant_TW.Big5 returns "Big5"
       es_ES at euro returns "ISO8859-15"
    
    as before, "C" and "POSIX" locales return "US-ASCII".  This is a big
    improvement.  The result of nl_langinfo can never be a zero-length
    string and it will always exclusively one of the values of the
    character maps of /usr/src/tools/tools/locale/etc/final-maps.

Summary of changes:
 lib/libc/locale/nl_langinfo.c   | 30 ++++++++++++++++++++++--------
 lib/libc/locale/setrunelocale.c |  2 +-
 usr.bin/localedef/wide.c        |  6 ++++--
 3 files changed, 27 insertions(+), 11 deletions(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/aafe6cccf26a84b0d7728fef5d976c0d6c09e3c6


-- 
DragonFly BSD source repository



More information about the Commits mailing list