diff options
| author | Joerg Wunsch <joerg@FreeBSD.org> | 1997-02-08 14:16:11 +0000 | 
|---|---|---|
| committer | Joerg Wunsch <joerg@FreeBSD.org> | 1997-02-08 14:16:11 +0000 | 
| commit | 2cd42b9ff96a4de0364dab9ae87f3641ce23d33f (patch) | |
| tree | 47ab477fcc0a4900c75e202e8e20a0c79118e8b3 | |
| parent | b8f0e2e3c7bec97d407f68a9c365e5d36b454dfb (diff) | |
Notes
| -rw-r--r-- | lib/libc/locale/collate.c | 4 | ||||
| -rw-r--r-- | lib/libc/locale/setlocale.c | 50 | ||||
| -rw-r--r-- | lib/libc/locale/setrunelocale.c | 7 | ||||
| -rw-r--r-- | lib/libc/stdtime/strftime.c | 7 | 
4 files changed, 29 insertions, 39 deletions
diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index 9189d7124dfe..a9907afc176e 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -24,7 +24,7 @@   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * SUCH DAMAGE.   * - * $Id: collate.c,v 1.8.2.3 1996/12/29 11:01:26 joerg Exp $ + * $Id: collate.c,v 1.8.2.4 1997/02/05 23:20:45 joerg Exp $   */  #include <rune.h> @@ -35,8 +35,8 @@  #include <unistd.h>  #include <sysexits.h>  #include "collate.h" +#include "setlocale.h" -char *_PathLocale;  int __collate_load_error = 1;  char __collate_version[STR_LEN];  u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 2d9293891576..6f3ea809ad3d 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -33,12 +33,12 @@   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * SUCH DAMAGE.   * - * $Id: setlocale.c,v 1.8.2.3 1997/02/05 23:20:51 joerg Exp $ + * $Id: setlocale.c,v 1.8.2.4 1997/02/06 08:32:55 pst Exp $   */  #ifdef LIBC_RCS  static const char rcsid[] = -	"$Id: setlocale.c,v 1.8.2.3 1997/02/05 23:20:51 joerg Exp $"; +	"$Id: setlocale.c,v 1.8.2.4 1997/02/06 08:32:55 pst Exp $";  #endif  #if defined(LIBC_SCCS) && !defined(lint) @@ -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)); @@ -98,6 +98,8 @@ extern int __time_load_locale __P((const char *)); /* strftime.c */  extern int _xpg4_setrunelocale __P((char *));  #endif +char	*_PathLocale; +  char *  setlocale(category, locale)  	int category; @@ -134,33 +136,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 +193,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()  { diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c index 42972065edca..d422e3998525 100644 --- a/lib/libc/locale/setrunelocale.c +++ b/lib/libc/locale/setrunelocale.c @@ -40,8 +40,7 @@  #include <string.h>  #include <stdio.h>  #include <stdlib.h> - -char *_PathLocale; +#include "setlocale.h"  extern int		_none_init __P((_RuneLocale *));  #ifdef XPG4 @@ -72,7 +71,7 @@ _xpg4_setrunelocale(encoding)  	char name[PATH_MAX];  	_RuneLocale *rl; -	if (!encoding) +	if (!encoding || strlen(encoding) > ENCODING_LEN)  	    return(EFAULT);  	/* @@ -85,7 +84,7 @@ _xpg4_setrunelocale(encoding)  	if (!_PathLocale)  		_PathLocale = _PATH_LOCALE; -	/* Range checking not needed, encoding has fixed size */ +	/* Range checking not needed, encoding length already checked above */  	(void) strcpy(name, _PathLocale);  	(void) strcat(name, "/");  	(void) strcat(name, encoding); diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index b2c8b42dfce1..332031b77a5d 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -17,7 +17,7 @@  #ifdef LIBC_RCS  static const char rcsid[] = -	"$Id: strftime.c,v 1.11.2.2 1996/12/29 11:01:36 joerg Exp $"; +	"$Id: strftime.c,v 1.11.2.3 1997/02/05 23:22:13 joerg Exp $";  #endif  #ifndef lint @@ -42,6 +42,7 @@ static const char	sccsid[] = "@(#)strftime.c	5.4 (Berkeley) 3/14/89";  #include <fcntl.h>  #include <locale.h>  #include <sys/stat.h> +#include "setlocale.h"  struct lc_time_T {  	const char *	mon[12]; @@ -461,8 +462,6 @@ _add(str, pt, ptlim)  	return pt;  } -extern char *_PathLocale; -  int  __time_load_locale(const char *name)  { @@ -509,7 +508,7 @@ __time_load_locale(const char *name)  	if (!_PathLocale)  		goto no_locale; -	/* Range checking not needed, name has fixed size */ +	/* Range checking not needed, 'name' size is limited */  	strcpy(filename, _PathLocale);  	strcat(filename, "/");  	strcat(filename, name);  | 
