Loading...
locale/FreeBSD/lnumeric.c Libc-1725.40.4 Libc-320
--- Libc/Libc-1725.40.4/locale/FreeBSD/lnumeric.c
+++ Libc/Libc-320/locale/FreeBSD/lnumeric.c
@@ -25,106 +25,68 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.16 2003/06/26 10:46:16 phantom Exp $");
-
-#include "xlocale_private.h"
+__FBSDID("$FreeBSD: src/lib/libc/locale/lnumeric.c,v 1.14 2003/03/20 08:05:20 ache Exp $");
 
 #include <limits.h>
-#include <string.h>
+#include "lnumeric.h"
+#include "ldpart.h"
 
-#include "ldpart.h"
-#include "lnumeric.h"
-
+extern int __nlocale_changed;
 extern const char *__fix_locale_grouping_str(const char *);
 
 #define LCNUMERIC_SIZE (sizeof(struct lc_numeric_T) / sizeof(char *))
 
+static char	numempty[] = { CHAR_MAX, '\0' };
+
 static const struct lc_numeric_T _C_numeric_locale = {
 	".",     	/* decimal_point */
 	"",     	/* thousands_sep */
-	""		/* grouping [C99 7.11.2.1]*/
+	numempty	/* grouping */
 };
 
-__private_extern__ int
-__numeric_load_locale(const char *name, locale_t loc)
+static struct lc_numeric_T _numeric_locale;
+static int	_numeric_using_locale;
+static char	*_numeric_locale_buf;
+
+int
+__numeric_load_locale(const char *name)
 {
 	int ret;
-	struct xlocale_numeric *xp;
-	static struct xlocale_numeric *cache = NULL;
 
-	/* 'name' must be already checked. */
-	if (strcmp(name, "C") == 0 || strcmp(name, "POSIX") == 0 ||
-	    strncmp(name, "C.", 2) == 0) {
-		if (!loc->_numeric_using_locale)
-			return (_LDP_CACHE);
-		loc->_numeric_using_locale = 0;
-		xlocale_release(loc->components[XLC_NUMERIC]);
-		loc->components[XLC_NUMERIC] = NULL;
-		loc->__nlocale_changed = 1;
-		return (_LDP_CACHE);
-	}
-
-	if (loc->_numeric_using_locale && strcmp(name, XLOCALE_NUMERIC(loc)->buffer) == 0)
-		return (_LDP_CACHE);
-	/*
-	 * If the locale name is the same as our cache, use the cache.
-	 */
-	if (cache && cache->buffer && strcmp(name, cache->buffer) == 0) {
-		loc->_numeric_using_locale = 1;
-		xlocale_release(loc->components[XLC_NUMERIC]);
-		loc->components[XLC_NUMERIC] = (void *)cache;
-		xlocale_retain(cache);
-		loc->__nlocale_changed = 1;
-		return (_LDP_CACHE);
-	}
-	if ((xp = (struct xlocale_numeric *)malloc(sizeof(*xp))) == NULL)
-		return _LDP_ERROR;
-	xp->header.header.retain_count = 1;
-	xp->header.header.destructor = destruct_ldpart;
-	xp->buffer = NULL;
-
-	ret = __part_load_locale(name, &loc->_numeric_using_locale,
-		&xp->buffer, "LC_NUMERIC",
+	ret = __part_load_locale(name, &_numeric_using_locale,
+		_numeric_locale_buf, "LC_NUMERIC",
 		LCNUMERIC_SIZE, LCNUMERIC_SIZE,
-		(const char **)&xp->locale);
+		(const char **)&_numeric_locale);
 	if (ret != _LDP_ERROR)
-		loc->__nlocale_changed = 1;
-	else
-		free(xp);
+		__nlocale_changed = 1;
 	if (ret == _LDP_LOADED) {
 		/* Can't be empty according to C99 */
-		if (*xp->locale.decimal_point == '\0')
-			xp->locale.decimal_point =
+		if (*_numeric_locale.decimal_point == '\0')
+			_numeric_locale.decimal_point =
 			    _C_numeric_locale.decimal_point;
-		xp->locale.grouping =
-		    __fix_locale_grouping_str(xp->locale.grouping);
-		xlocale_release(loc->components[XLC_NUMERIC]);
-		loc->components[XLC_NUMERIC] = (void *)xp;
-		xlocale_release(cache);
-		cache = xp;
-		xlocale_retain(cache);
+		_numeric_locale.grouping =
+		    __fix_locale_grouping_str(_numeric_locale.grouping);
 	}
 	return (ret);
 }
 
-__private_extern__ struct lc_numeric_T *
-__get_current_numeric_locale(locale_t loc)
+struct lc_numeric_T *
+__get_current_numeric_locale(void)
 {
-	return (loc->_numeric_using_locale
-		? &XLOCALE_NUMERIC(loc)->locale
+	return (_numeric_using_locale
+		? &_numeric_locale
 		: (struct lc_numeric_T *)&_C_numeric_locale);
 }
 
 #ifdef LOCALE_DEBUG
 void
 numericdebug(void) {
-locale_t loc = __current_locale();
 printf(	"decimal_point = %s\n"
 	"thousands_sep = %s\n"
 	"grouping = %s\n",
-	XLOCALE_NUMERIC(loc)->locale.decimal_point,
-	XLOCALE_NUMERIC(loc)->locale.thousands_sep,
-	XLOCALE_NUMERIC(loc)->locale.grouping
+	_numeric_locale.decimal_point,
+	_numeric_locale.thousands_sep,
+	_numeric_locale.grouping
 );
 }
 #endif /* LOCALE_DEBUG */