Comment 76 for bug 10910

Revision history for this message
In , Markus Kuhn (markus-kuhn) wrote :

Just for the record: only on glibc systems, an API for interpreting the LC_PAPER aspect of the locale setting is

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

int main()
{
  if (!setlocale(LC_PAPER, "")) {
    fprintf(stderr, "Can't set the specified locale! "
            "Check LANG, LC_PAPER, LC_ALL.\n");
    return 1;
  }
  printf("paper height = %d mm\n", (int) nl_langinfo(_NL_PAPER_HEIGHT));
  printf("paper width = %d mm\n", (int) nl_langinfo(_NL_PAPER_WIDTH));
  return 0;
}

which results in

$ LC_ALL=en_GB.UTF-8 ./lc_paper
paper height = 297 mm
paper width = 210 mm
$ LC_ALL=en_US.UTF-8 ./lc_paper
paper height = 279 mm
paper width = 216 mm
$ LC_ALL=en_CA.UTF-8 ./lc_paper
paper height = 279 mm
paper width = 216 mm

I just checked with

  for l in `locale -a` ; do echo $l: ; LC_ALL=$l ./lc_paper ; done

all glibc locales on openSUSE 10.3 and found in addition to US and CA only one other country code whose locales specify the U.S. Letter format: PR = Puerto Rico.

So please change in my original test code the term

  strstr(s, "_US") || strstr(s, "_CA")

into

  strstr(s, "_US") || strstr(s, "_CA") || strstr(s, "_PR")

to make its results compatible with glibc.