[cups.bugs] Re: [MOD] STR #1194: CUPS uses LC_MESSAGES to determine

Markus Kuhn Markus.Kuhn at cl.cam.ac.uk
Fri Jun 10 05:54:34 PDT 2005


[STR New]

In a nutshell, the portable way any application should determine today on
POSIX systems the character set selected by the locale is:

--------------------------------------------------------------
#include <stdio.h>
#include <langinfo.h>
#include <locale.h>

int main()
{
  if (!setlocale(LC_CTYPE, "")) {
    fprintf(stderr, "Can't set the specified locale! "
            "Check LANG, LC_CTYPE, LC_ALL.\n");
    return 1;
  }
  puts(nl_langinfo(CODESET));
  return 0;
}
--------------------------------------------------------------

This is formally guaranteed by the POSIX spec to work on any system where

  _POSIX_VERSION >= 200112L

but it will work in practice almost anywhere else, too.

Unfortunately, the output syntax of nl_langinfo(CODESET) is not
standardized properly. In practice, UTF-8 is always signalled as "UTF-8",
but ISO 8859-15 can come as "ISO8859-15", "ISO_8859-15", "ISO-8859-15",
etc.

Therefore, it is a good idea to normalize the output of
nl_langinfo(CODESET), and the simple public-domain function

  http://www.cl.cam.ac.uk/~mgk25/ucs/norm_charmap.c

can be used to do exactly that.

Link: http://www.cups.org/str.php?L1194
Version: 1.1.23





More information about the cups mailing list