diff options
author | Andrey A. Chernov <ache@FreeBSD.org> | 1996-11-26 08:00:17 +0000 |
---|---|---|
committer | Andrey A. Chernov <ache@FreeBSD.org> | 1996-11-26 08:00:17 +0000 |
commit | 40c0625e97dd440f46a2fae4845c4a5a32227209 (patch) | |
tree | 599db93c53cdda5c9f12f78ca7a23a9860c0364a /lib/libc/locale | |
parent | 2f5f1c05dbb2d21d3f92a100e4d3112bb2799d15 (diff) | |
download | src-40c0625e97dd440f46a2fae4845c4a5a32227209.tar.gz src-40c0625e97dd440f46a2fae4845c4a5a32227209.zip |
Add Id
Optimize/improve recently added locale restoration on failure
Notes
Notes:
svn path=/head/; revision=19971
Diffstat (limited to 'lib/libc/locale')
-rw-r--r-- | lib/libc/locale/setlocale.c | 78 |
1 files changed, 43 insertions, 35 deletions
diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 9bcb88a27115..85cedb82c9b6 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -32,6 +32,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -107,10 +109,8 @@ setlocale(category, locale) /* * Default to the current locale for everything. */ - for (i = 1; i < _LC_LAST; ++i) { + for (i = 1; i < _LC_LAST; ++i) (void)strcpy(new_categories[i], current_categories[i]); - (void)strcpy(saved_categories[i], current_categories[i]); - } /* * Now go fill up new_categories from the locale argument @@ -165,17 +165,11 @@ setlocale(category, locale) } } - if (category) { - if ((r = loadlocale(category)) == NULL) { - (void)strcpy(new_categories[category], - saved_categories[category]); - /* XXX can fail too */ - (void)loadlocale(category); - } - return (r); - } + if (category) + return (loadlocale(category)); - for (i = 1; i < _LC_LAST; ++i) + for (i = 1; i < _LC_LAST; ++i) { + (void)strcpy(saved_categories[i], current_categories[i]); if (loadlocale(i) == NULL) { for (j = 1; j < i; j++) { (void)strcpy(new_categories[j], @@ -185,6 +179,7 @@ setlocale(category, locale) } return (NULL); } + } return (currentlocale()); } @@ -226,14 +221,15 @@ static char * loadlocale(category) int category; { - char *encoding = new_categories[category]; + char *ret; + char *new = new_categories[category]; + char *old = current_categories[category]; - if (strcmp(encoding, - current_categories[category]) == 0) - return (current_categories[category]); + if (strcmp(new, old) == 0) + return (old); if ( !_PathLocale - && strcmp(encoding, "C") && strcmp(encoding, "POSIX") + && strcmp(new, "C") && strcmp(new, "POSIX") ) { char *pl = getenv("PATH_LOCALE"); @@ -247,34 +243,46 @@ loadlocale(category) if (category == LC_CTYPE) { #ifdef XPG4 - if (_xpg4_setrunelocale(encoding)) + ret = _xpg4_setrunelocale(new) ? NULL : new; #else - if (setrunelocale(encoding)) + ret = setrunelocale(new) ? NULL : new; #endif - return (NULL); - (void)strcpy(current_categories[LC_CTYPE], encoding); - return (current_categories[LC_CTYPE]); + if (!ret) { +#ifdef XPG4 + (void)_xpg4_setrunelocale(old); +#else + (void)setrunelocale(old); +#endif + } else + (void)strcpy(old, new); + return (ret); } if (category == LC_COLLATE) { - if (__collate_load_tables(encoding) < 0) - return (NULL); - (void)strcpy(current_categories[LC_COLLATE], encoding); - return (current_categories[LC_COLLATE]); + ret = (__collate_load_tables(new) < 0) ? NULL : new; + if (!ret) + (void)__collate_load_tables(old); + else + (void)strcpy(old, new); + return (ret); } if (category == LC_TIME) { - if (__time_load_locale(encoding) < 0) - return (NULL); - (void)strcpy(current_categories[LC_TIME], encoding); - return (current_categories[LC_TIME]); + ret = (__time_load_locale(new) < 0) ? NULL : new; + if (!ret) + (void)__time_load_locale(old); + else + (void)strcpy(old, new); + return (ret); } if (category == LC_MONETARY || category == LC_NUMERIC) { - if (stub_load_locale(encoding)) - return (NULL); - (void)strcpy(current_categories[category], encoding); - return (current_categories[category]); + ret = stub_load_locale(new) ? NULL : new; + if (!ret) + (void)stub_load_locale(old); + else + (void)strcpy(old, new); + return (ret); } /* Just in case...*/ |