Project

General

Profile

Bug #142

locale support not POSIX compliant

Added by Garrett D'Amore over 9 years ago. Updated over 9 years ago.

Status:
Resolved
Priority:
Normal
Category:
-
Start date:
2010-09-03
Due date:
% Done:

100%

Estimated time:
3.00 h
Difficulty:
Tags:

Description

Joerg has indicated that only LANG is properly honored in the locale support. The following was reported:

The reason why the i18n code does not work correctly is that the order of the 
locale names did change.

Currently only setting LANG has the desired effect, but LANG should have the 
lowes priority after LC_* while LC_ALL should have the highest priority.

The original order in locale.c:

/* 
 * Category names for getenv() 
 */ 
static char *categories[_LC_LAST] = { 
    "LC_ALL", 
    "LC_COLLATE", 
    "LC_CTYPE", 
    "LC_MONETARY", 
    "LC_NUMERIC", 
    "LC_TIME", 
    "LC_MESSAGES", 
}; 

works as expected. 

If you change this order, you of course also need to change any code that 
depends on the order of this array. This is e.g. 

static const char * 
__get_locale_env(category) 
        int category; 
{ 
        const char *env; 

        /* 1. check LC_ALL. */ 
        env = getenv(categories[0]); 

        /* 2. check LC_* */ 
        if (env == NULL || !*env) 
                env = getenv(categories[category]); 

        /* 3. check LANG */ 
        if (env == NULL || !*env) 
                env = getenv("LANG"); 

        /* 4. if none is set, fall to "C" */ 
        if (env == NULL || !*env) 
                env = "C"; 

        return (env); 
} 

It turns out that he also identified a problem with an unitialized reference to buf after being alloca'd.

The code was totally busted.

Joerg gave some code that I used as a starting point, but I've also made some changes of my own to make it better, fixing the alloca problem, making it more readable, and verifying the correct functionality for composite locales, which I don't think ever worked properly.

Now everything seems to work, and setlocale() appears to honor the POSIX precedence rules for environment variables.

Diffs coming shortly.


Files

t.c (600 Bytes) t.c This is a simple program I used to test setlocale with. Garrett D'Amore, 2010-09-03 01:24 AM

History

#2

Updated by Garrett D'Amore over 9 years ago

  • % Done changed from 0 to 90
#3

Updated by Garrett D'Amore over 9 years ago

#4

Updated by Garrett D'Amore over 9 years ago

  • Status changed from In Progress to Resolved

I integrated this last night.

#5

Updated by Garrett D'Amore over 9 years ago

  • % Done changed from 90 to 100

Also available in: Atom PDF