diff options
author | ache <ache@FreeBSD.org> | 1997-02-06 09:11:06 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-02-06 09:11:06 +0000 |
commit | 1fbffa765c7c52ab4eb89108096c207c562589d6 (patch) | |
tree | 884ff88fa55071e0b114b7047342a5e92e455a11 /lib/libc/locale/setlocale.c | |
parent | b7c9a718d55bb2dfd777c2f469f9a99c4cceae19 (diff) | |
download | FreeBSD-src-1fbffa765c7c52ab4eb89108096c207c562589d6.zip FreeBSD-src-1fbffa765c7c52ab4eb89108096c207c562589d6.tar.gz |
Use symbolic constants instead of hardcoded digits
Add range check for setrunelocale since it can be called
directly.
Remove _startup_setlocale compatibility function
Should go into 2.2
Diffstat (limited to 'lib/libc/locale/setlocale.c')
-rw-r--r-- | lib/libc/locale/setlocale.c | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 686e36d..656ed85 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -54,6 +54,7 @@ static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; #include <string.h> #include <unistd.h> #include "collate.h" +#include "setlocale.h" /* * Category names for getenv() @@ -70,7 +71,7 @@ static char *categories[_LC_LAST] = { /* * Current locales for each category */ -static char current_categories[_LC_LAST][32] = { +static char current_categories[_LC_LAST][ENCODING_LEN + 1] = { "C", "C", "C", @@ -82,11 +83,10 @@ static char current_categories[_LC_LAST][32] = { /* * The locales we are going to try and load */ -static char new_categories[_LC_LAST][32]; -static char saved_categories[_LC_LAST][32]; +static char new_categories[_LC_LAST][ENCODING_LEN + 1]; +static char saved_categories[_LC_LAST][ENCODING_LEN + 1]; -static char current_locale_string[_LC_LAST * 33]; -char *_PathLocale; +static char current_locale_string[_LC_LAST * (ENCODING_LEN + 1/*"/"*/ + 1)]; static char *currentlocale __P((void)); static char *loadlocale __P((int)); @@ -134,33 +134,34 @@ setlocale(category, locale) if (!env || !*env) env = "C"; - (void) strncpy(new_categories[category], env, 31); - new_categories[category][31] = 0; + (void) strncpy(new_categories[category], env, ENCODING_LEN); + new_categories[category][ENCODING_LEN] = '\0'; if (category == LC_ALL) { for (i = 1; i < _LC_LAST; ++i) { if (!(env = getenv(categories[i])) || !*env) env = new_categories[LC_ALL]; - (void)strncpy(new_categories[i], env, 31); - new_categories[i][31] = 0; + (void)strncpy(new_categories[i], env, ENCODING_LEN); + new_categories[i][ENCODING_LEN] = '\0'; } } } else if (category != LC_ALL) { - (void)strncpy(new_categories[category], locale, 31); - new_categories[category][31] = 0; + (void)strncpy(new_categories[category], locale, ENCODING_LEN); + new_categories[category][ENCODING_LEN] = '\0'; } else { - if ((r = strchr(locale, '/')) == 0) { + if ((r = strchr(locale, '/')) == NULL) { for (i = 1; i < _LC_LAST; ++i) { - (void)strncpy(new_categories[i], locale, 31); - new_categories[i][31] = 0; + (void)strncpy(new_categories[i], locale, ENCODING_LEN); + new_categories[i][ENCODING_LEN] = '\0'; } } else { for (i = 1; r[1] == '/'; ++r); if (!r[1]) return (NULL); /* Hmm, just slashes... */ do { - len = r - locale > 31 ? 31 : r - locale; + len = r - locale > ENCODING_LEN ? ENCODING_LEN : r - locale; (void)strncpy(new_categories[i], locale, len); - new_categories[i++][len] = 0; + new_categories[i][len] = '\0'; + i++; locale = r; while (*locale == '/') ++locale; @@ -190,17 +191,6 @@ setlocale(category, locale) return (currentlocale()); } -/* To be compatible with crt0 hack */ -void -_startup_setlocale(category, locale) - int category; - const char *locale; -{ -#ifndef XPG4 - (void) setlocale(category, locale); -#endif -} - static char * currentlocale() { |