From 0adcaceb0f994829287e5c6b7a8730510851c2bc Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Fri, 5 Oct 2001 02:10:46 +0000 Subject: [PATCH] ICU-1257 Call setlocale only once. We don't want /en_US/C/C/C/C/C on the second try from Solaris. X-SVN-Rev: 6070 --- icu4c/source/common/putil.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/icu4c/source/common/putil.c b/icu4c/source/common/putil.c index e96a97bfda..940e580524 100644 --- a/icu4c/source/common/putil.c +++ b/icu4c/source/common/putil.c @@ -1123,19 +1123,32 @@ static const mac_lc_rec mac_lc_recs[] = { /* Return just the POSIX id, whatever happens to be in it */ static const char *uprv_getPOSIXID() { - const char* posixID = getenv("LC_ALL"); - if (posixID == 0) - posixID = getenv("LANG"); - if (posixID == 0) - posixID = setlocale(LC_ALL, NULL); + static const char* posixID = NULL; + if (posixID == 0) { + posixID = getenv("LC_ALL"); + if (posixID == 0) { + posixID = getenv("LANG"); + if (posixID == 0) { + /* + * On Solaris two different calls to setlocale can result in + * different values. Only get this value once. + */ + posixID = setlocale(LC_ALL, NULL); + } + } + } if (posixID==0) { + /* Nothing worked. Give it a nice value. */ posixID = "en_US"; } - else if ((uprv_strcmp("C", posixID) == 0) || - (uprv_strncmp("C ", posixID, 2) == 0)) - { /* HPUX returns 'C C C C C C C' */ + else if ((uprv_strcmp("C", posixID) == 0) + || (uprv_strchr(posixID, ' ') != NULL) + || (uprv_strchr(posixID, '/') != NULL)) + { /* HPUX returns 'C C C C C C C' */ + /* Solaris can return /en_US/C/C/C/C/C on the second try. */ + /* Maybe we got some garbage. Give it a nice value. */ posixID = "en_US_POSIX"; } return posixID;