locale is broken. setlocale does not return expected results.

Bug #51624 reported by Jay R. Wren
6
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

calls to setlocale fail. This effects perl POSIX's setlocale as well.

Test case:

#include<stdio.h>
#include<locale.h>
int main(int argc,char** argv)
{
        char* locale="en_US";
        if (argc>1)
                locale=argv[1];
        char* lres = setlocale(LC_ALL, locale);
        if (lres != NULL)
                printf("%d:%s\n",LC_ALL, lres);
}

EXPECTED RESULT:
setlocale(LC_ALL, "en_US") ;
should return a pointer to a char* saying "en_US".

Note: the original reporter indicated the bug was in package 'libc'; however, that package was not published in Ubuntu.

Revision history for this message
Jay R. Wren (evarlast) wrote :

looks like this effects many program, such as aspell

$ cat /etc/passwd|aspell -a
Error: No word lists can be found for the language "en_US".
$

Revision history for this message
Moises Silva (moises-silva) wrote :

I have the same issue. Im attaching my test program.

setlocale is returning NULL

the same program runs fine on suse and gentoo.

Is this a libc issue? does ubuntu modify libc?

Thanks

Revision history for this message
Xeno Campanoli (xeno) wrote :

All the documents I'm seeing indicate you MAY NEED to pass "NULL" to setlocale to get the locale string back. On Feisty, when I run it this way, I get "C" back for my locale. Perhaps that is still wrong, but at least it's not the result above.

Here are a couple of URLs:

http://www.gnu.org/software/libc/manual/html_mono/libc.html
where there's the statement:
"You can also use this function to find out the current locale by passing a null pointer as the locale argument. In this case, setlocale returns a string that is the name of the locale currently selected for category category."

And in:
http://www.cppreference.com/stddate/all.html
You have the following statement:

"The setlocale() function is used to set and retrieve the current locale. If locale is NULL, the current locale is returned. Otherwise, locale is used to set the locale for the given category."

I believe that implies it doesn't give you a string otherwise, or at worst, nobody ever used it like that, and it is no longer maintained to do so. It's unfortunate that the documentation is not more specific, but the first one is pretty canonical.

Revision history for this message
Xeno Campanoli (xeno) wrote :

I appear to get good results on feisty from the aspell example above too:

cat /etc/passwd|aspell -a
.
.
.
*
& ubu 100 61: bu, usu, buy, uni, Bi, UN, UV, Yb, bi, bub, bur, by, Abeu, Ibo, Oby, obi, B, U, b, u, Rubi, Ruby, cub, dub, hub, nub, pub, rub, ruby, sub, tub, AB, Ab, Eb, OB, Ob, ab, ob, IBM, IOU, abut, FBI, ICU, RBI, UPI, Una, Urdu, Uri, Uzi, Aube, Au, BA, BB, BO, Ba, Be, Bo, CB, Cb, EU, Eu, GB, KB, Kb, MB, Mb, NB, Nb, Pb, QB, Rb, Sb, TB, Tb, UK, UL, US, UT, Ur, be, dB, db, lb, uh, um, up, us, vb, ABA, Abe, Eba, ebb, Cebu, Cuba, Hube, Rube, bubo, cube, lube, rube
*
*
---snip---

Revision history for this message
Xeno Campanoli (xeno) wrote :

It appears to me this can be safely closed for Feisty, unless Wren or others are still getting their symptoms. I'm clearly not on Feisty.

Revision history for this message
Jay R. Wren (evarlast) wrote :

I'm running fine now. Thank you

+1 to close.

Revision history for this message
Xeno Campanoli (xeno) wrote :

I'm not sure if rejected is right. Perhaps fixed. Anyway, we seem to have confirmed that it's no longer a problem in Feisty. Please feel welcome to change the status if I've done it wrong.

xc

Changed in glibc:
status: Unconfirmed → Rejected
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.