mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-03-01 12:35:44 +08:00
Add __get_C_locale inline function and fix new locale code for !_MB_CAPABLE targets
Only access "C" locale using the new __get_C_locale inline function. Enable __global_locale for !_MB_CAPABLE targets. Accommodate !_MB_CAPABLE targets in new locale code. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
2ea3993619
commit
3f36c6fa62
@ -45,12 +45,15 @@ _duplocale_r (struct _reent *p, struct __locale_t *locobj)
|
|||||||
struct __locale_t tmp_locale, *new_locale;
|
struct __locale_t tmp_locale, *new_locale;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
#ifndef _MB_CAPABLE
|
||||||
|
return __get_C_locale ();
|
||||||
|
#else /* _MB_CAPABLE */
|
||||||
/* LC_GLOBAL_LOCALE denotes the global locale. */
|
/* LC_GLOBAL_LOCALE denotes the global locale. */
|
||||||
if (locobj == LC_GLOBAL_LOCALE)
|
if (locobj == LC_GLOBAL_LOCALE)
|
||||||
locobj = __get_global_locale ();
|
locobj = __get_global_locale ();
|
||||||
/* The "C" locale is used statically, never copied. */
|
/* The "C" locale is used statically, never copied. */
|
||||||
else if (locobj == &__C_locale)
|
else if (locobj == __get_C_locale ())
|
||||||
return (struct __locale_t *) &__C_locale;
|
return __get_C_locale ();
|
||||||
/* Copy locale content. */
|
/* Copy locale content. */
|
||||||
tmp_locale = *locobj;
|
tmp_locale = *locobj;
|
||||||
#ifdef __HAVE_LOCALE_INFO__
|
#ifdef __HAVE_LOCALE_INFO__
|
||||||
@ -86,6 +89,7 @@ error:
|
|||||||
#endif /* __HAVE_LOCALE_INFO__ */
|
#endif /* __HAVE_LOCALE_INFO__ */
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif /* _MB_CAPABLE */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _REENT_ONLY
|
#ifndef _REENT_ONLY
|
||||||
|
@ -40,8 +40,10 @@ PORTABILITY
|
|||||||
void
|
void
|
||||||
_freelocale_r (struct _reent *p, struct __locale_t *locobj)
|
_freelocale_r (struct _reent *p, struct __locale_t *locobj)
|
||||||
{
|
{
|
||||||
|
/* Nothing to do on !_MB_CAPABLE targets. */
|
||||||
|
#ifdef _MB_CAPABLE
|
||||||
/* Sanity check. The "C" locale is static, don't try to free it. */
|
/* Sanity check. The "C" locale is static, don't try to free it. */
|
||||||
if (!locobj || locobj == &__C_locale || locobj == LC_GLOBAL_LOCALE)
|
if (!locobj || locobj == __get_C_locale () || locobj == LC_GLOBAL_LOCALE)
|
||||||
return;
|
return;
|
||||||
#ifdef __HAVE_LOCALE_INFO__
|
#ifdef __HAVE_LOCALE_INFO__
|
||||||
for (int i = 1; i < _LC_LAST; ++i)
|
for (int i = 1; i < _LC_LAST; ++i)
|
||||||
@ -52,6 +54,7 @@ _freelocale_r (struct _reent *p, struct __locale_t *locobj)
|
|||||||
}
|
}
|
||||||
#endif /* __HAVE_LOCALE_INFO__ */
|
#endif /* __HAVE_LOCALE_INFO__ */
|
||||||
_free_r (p, locobj);
|
_free_r (p, locobj);
|
||||||
|
#endif /* _MB_CAPABLE */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -203,6 +203,7 @@ static char *categories[_LC_LAST] = {
|
|||||||
"LC_TIME",
|
"LC_TIME",
|
||||||
"LC_MESSAGES",
|
"LC_MESSAGES",
|
||||||
};
|
};
|
||||||
|
#endif /* _MB_CAPABLE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default locale per POSIX. Can be overridden on a per-target base.
|
* Default locale per POSIX. Can be overridden on a per-target base.
|
||||||
@ -210,6 +211,8 @@ static char *categories[_LC_LAST] = {
|
|||||||
#ifndef DEFAULT_LOCALE
|
#ifndef DEFAULT_LOCALE
|
||||||
#define DEFAULT_LOCALE "C"
|
#define DEFAULT_LOCALE "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef _MB_CAPABLE
|
||||||
/*
|
/*
|
||||||
* This variable can be changed by any outside mechanism. This allows,
|
* This variable can be changed by any outside mechanism. This allows,
|
||||||
* for instance, to load the default locale from a file.
|
* for instance, to load the default locale from a file.
|
||||||
@ -250,6 +253,7 @@ const struct __locale_t __C_locale =
|
|||||||
},
|
},
|
||||||
#endif /* __HAVE_LOCALE_INFO__ */
|
#endif /* __HAVE_LOCALE_INFO__ */
|
||||||
};
|
};
|
||||||
|
#endif /* _MB_CAPABLE */
|
||||||
|
|
||||||
struct __locale_t __global_locale =
|
struct __locale_t __global_locale =
|
||||||
{
|
{
|
||||||
@ -291,6 +295,7 @@ struct __locale_t __global_locale =
|
|||||||
#endif /* __HAVE_LOCALE_INFO__ */
|
#endif /* __HAVE_LOCALE_INFO__ */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef _MB_CAPABLE
|
||||||
/* Renamed from current_locale_string to make clear this is only the
|
/* Renamed from current_locale_string to make clear this is only the
|
||||||
*global* string for setlocale (LC_ALL, NULL). There's no equivalent
|
*global* string for setlocale (LC_ALL, NULL). There's no equivalent
|
||||||
functionality for uselocale. */
|
functionality for uselocale. */
|
||||||
|
@ -86,6 +86,9 @@ struct __locale_t *
|
|||||||
_newlocale_r (struct _reent *p, int category_mask, const char *locale,
|
_newlocale_r (struct _reent *p, int category_mask, const char *locale,
|
||||||
struct __locale_t *base)
|
struct __locale_t *base)
|
||||||
{
|
{
|
||||||
|
#ifndef _MB_CAPABLE
|
||||||
|
return __get_C_locale ();
|
||||||
|
#else /* _MB_CAPABLE */
|
||||||
char new_categories[_LC_LAST][ENCODING_LEN + 1];
|
char new_categories[_LC_LAST][ENCODING_LEN + 1];
|
||||||
struct __locale_t tmp_locale, *new_locale;
|
struct __locale_t tmp_locale, *new_locale;
|
||||||
int i;
|
int i;
|
||||||
@ -108,9 +111,9 @@ _newlocale_r (struct _reent *p, int category_mask, const char *locale,
|
|||||||
if ((!base && category_mask == 0)
|
if ((!base && category_mask == 0)
|
||||||
|| (category_mask == LC_VALID_MASK
|
|| (category_mask == LC_VALID_MASK
|
||||||
&& (!strcmp (locale, "C") || !strcmp (locale, "POSIX"))))
|
&& (!strcmp (locale, "C") || !strcmp (locale, "POSIX"))))
|
||||||
return (struct __locale_t *) &__C_locale;
|
return __get_C_locale ();
|
||||||
/* Start with setting all values to the default locale values. */
|
/* Start with setting all values to the default locale values. */
|
||||||
tmp_locale = __C_locale;
|
tmp_locale = *__get_C_locale ();
|
||||||
/* Fill out new category strings. */
|
/* Fill out new category strings. */
|
||||||
for (i = 1; i < _LC_LAST; ++i)
|
for (i = 1; i < _LC_LAST; ++i)
|
||||||
{
|
{
|
||||||
@ -206,6 +209,7 @@ error:
|
|||||||
#endif /* __HAVE_LOCALE_INFO__ */
|
#endif /* __HAVE_LOCALE_INFO__ */
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif /* _MB_CAPABLE */
|
||||||
}
|
}
|
||||||
|
|
||||||
struct __locale_t *
|
struct __locale_t *
|
||||||
|
@ -194,9 +194,10 @@ struct __locale_t
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct __locale_t __C_locale;
|
#ifdef _MB_CAPABLE
|
||||||
extern char *__loadlocale (struct __locale_t *, int, const char *);
|
extern char *__loadlocale (struct __locale_t *, int, const char *);
|
||||||
extern const char *__get_locale_env(struct _reent *, int);
|
extern const char *__get_locale_env(struct _reent *, int);
|
||||||
|
#endif /* _MB_CAPABLE */
|
||||||
|
|
||||||
extern struct lconv *__localeconv_l (struct __locale_t *locale);
|
extern struct lconv *__localeconv_l (struct __locale_t *locale);
|
||||||
|
|
||||||
@ -229,6 +230,19 @@ __get_current_locale ()
|
|||||||
return _REENT->_locale ?: __get_global_locale ();
|
return _REENT->_locale ?: __get_global_locale ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Only access fixed "C" locale using this function. Fake for !_MB_CAPABLE
|
||||||
|
targets by returning ptr to globale locale. */
|
||||||
|
_ELIDABLE_INLINE struct __locale_t *
|
||||||
|
__get_C_locale ()
|
||||||
|
{
|
||||||
|
#ifndef _MB_CAPABLE
|
||||||
|
return __get_global_locale ();
|
||||||
|
#else
|
||||||
|
extern const struct __locale_t __C_locale;
|
||||||
|
return (struct __locale_t *) &__C_locale;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
_ELIDABLE_INLINE const struct lc_collate_T *
|
_ELIDABLE_INLINE const struct lc_collate_T *
|
||||||
__get_collate_locale (struct __locale_t *locale)
|
__get_collate_locale (struct __locale_t *locale)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user