diff options
author | Karl Williamson <khw@cpan.org> | 2017-03-24 19:01:39 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-11-06 12:55:57 -0700 |
commit | d5e32b932ce9902855a6a3afe374f68e28e2d701 (patch) | |
tree | 395e59ddbc5dd825525b5a97bb07db8c755b69ff /locale.c | |
parent | cd999af93305983fce668cb62d89ab1f1b7d0ca5 (diff) | |
download | perl-d5e32b932ce9902855a6a3afe374f68e28e2d701.tar.gz |
locale.c: Tighten what is considered a LC variable
Things like LC_CTYPE are locale variables, but not LC_ctype nor
LC__CTYPE. Prior to this commit all were treated as locale variables.
Many platforms have more locale variables than Perl knows about, e.g.,
LC_PAPER, and the code tries to catch all possibilities.
Diffstat (limited to 'locale.c')
-rw-r--r-- | locale.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -1689,7 +1689,6 @@ Perl_init_i18nl10n(pTHX_ int printwarn) const char * const lang = savepv(PerlEnv_getenv("LANG")); bool setlocale_failure = FALSE; unsigned int i; - char *p; /* A later getenv() could zap this, so only use here */ const char * const bad_lang_use_once = PerlEnv_getenv("PERL_BADLANG"); @@ -1970,13 +1969,24 @@ Perl_init_i18nl10n(pTHX_ int printwarn) #if defined(USE_ENVIRON_ARRAY) { char **e; + + /* Look through the environment for any variables of the + * form qr/ ^ LC_ [A-Z]+ = /x, except LC_ALL which was + * already handled above. These are assumed to be locale + * settings. Output them and their values. */ for (e = environ; *e; e++) { + const STRLEN prefix_len = sizeof("LC_") - 1; + STRLEN uppers_len; + if ( strBEGINs(*e, "LC_") && ! strBEGINs(*e, "LC_ALL=") - && (p = strchr(*e, '='))) + && (uppers_len = strspn(*e + prefix_len, + "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) + && ((*e)[prefix_len + uppers_len] == '=')) { PerlIO_printf(Perl_error_log, "\t%.*s = \"%s\",\n", - (int)(p - *e), *e, p + 1); + (int) (prefix_len + uppers_len), *e, + *e + prefix_len + uppers_len + 1); } } } |