[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#627355: libc6: setlocale(LC_ALL,"C") sometimes fails to reset locale to C



Package: libc6
Version: 2.11.2-10
Severity: normal



Dear package maintainers,

I believe that calling setlocale(LC_ALL, "C") should always restore 
the locale to C in all locale categories, even if you have previously called
setlocale(LC_CTYPE).  It turns out that libc sometimes does not behave like
this: the previous locale can sometimes remain in effect in some categories.

Here's an example.  Before you test this, please make sure that the locale
en_US.iso88591 is installed on your system.  You should not set any locale
environment variables for this test, as the example program arranges to set
them them.


[am]king ~/a/tmp$ cat a.c
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>
int main(void) {
	unsetenv("LC_ALL");
	unsetenv("LC_NUMERIC");
	setenv("LC_CTYPE", "en_US.iso88591", 1);
	unsetenv("LANG");
	printf("setlocale(LC_ALL, \"\") => \"%s\"\n", 
			setlocale(LC_ALL, ""));
	printf("setlocale(LC_NUMERIC, \"\") => \"%s\"\n", 	
			setlocale(LC_NUMERIC, ""));
	printf("setlocale(LC_ALL, \"C\") => \"%s\"\n", 
			setlocale(LC_ALL, "C"));
	printf("setlocale(LC_CTYPE, NULL) => \"%s\" (should be \"C\")\n", 
			setlocale(LC_CTYPE, NULL));
	printf("tolower(201) => %d (should be 201)\n", 
			tolower(201));
	return 0;
}
[am]king ~/a/tmp$ /usr/bin/gcc -Wall -O -o a a.c
[am]king ~/a/tmp$ ./a
setlocale(LC_ALL, "") =>
"LC_CTYPE=en_US.iso88591;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C"
setlocale(LC_NUMERIC, "") => "C"
setlocale(LC_ALL, "C") => "C"
setlocale(LC_CTYPE, NULL) => "en_US.iso88591" (should be "C")
tolower(201) => 233 (should be 201)
[am]king ~/a/tmp$ 


In the above example, it seems that the CTYPE locale remains en_US.iso88591
after the call setlocale(LC_ALL, "C"), which is a bug.


-- System Information:
Debian Release: 6.0.1
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.37 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=hu_HU (charmap=ISO-8859-2)
Shell: /bin/sh linked to /bin/bash

Versions of packages libc6 depends on:
ii  libc-bin                      2.11.2-10  Embedded GNU C Library: Binaries
ii  libgcc1                       1:4.4.5-8  GCC support library

libc6 recommends no packages.

Versions of packages libc6 suggests:
ii  debconf [debconf-2.0]         1.5.36.1   Debian configuration management sy
ii  glibc-doc                     2.11.2-10  Embedded GNU C Library: Documentat
ii  locales                       2.11.2-10  Embedded GNU C Library: National L

-- debconf information:
  glibc/upgrade: true
* glibc/disable-screensaver:
  glibc/restart-failed:
* glibc/restart-services: exim4 cups cron apache2



Reply to: