[PATCH 3/3] Remove locale access for _REENT_SMALL
Jaap de Wolff
info@jasoon.nl
Fri Feb 16 18:46:00 GMT 2018
---
newlib/libc/locale/duplocale.c | 6 ++++++
newlib/libc/locale/locale.c | 27 ++++++++++++++++++++++++++-
newlib/libc/locale/localeconv.c | 6 ++++++
newlib/libc/locale/newlocale.c | 5 +++++
newlib/libc/locale/nl_langinfo.c | 8 ++++++++
newlib/libc/locale/setlocale.h | 34 ++++++++++++++++++++++++++++++----
newlib/libc/locale/uselocale.c | 6 ++++++
7 files changed, 87 insertions(+), 5 deletions(-)
diff --git a/newlib/libc/locale/duplocale.c b/newlib/libc/locale/duplocale.c
index d3e7d782e..432c512f1 100644
--- a/newlib/libc/locale/duplocale.c
+++ b/newlib/libc/locale/duplocale.c
@@ -35,6 +35,7 @@ PORTABILITY
*/
#include <newlib.h>
+#include <errno.h>
#include <reent.h>
#include <stdlib.h>
#include "setlocale.h"
@@ -42,6 +43,10 @@ PORTABILITY
struct __locale_t *
_duplocale_r (struct _reent *p, struct __locale_t *locobj)
{
+#ifdef _REENT_SMALL
+ p->_errno = ENOMEM;
+ return (locale_t)0;
+#else
struct __locale_t tmp_locale, *new_locale;
int i;
@@ -91,6 +96,7 @@ error:
return NULL;
#endif /* _MB_CAPABLE */
+#endif /* _REENT_SMALL */
}
#ifndef _REENT_ONLY
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index baa5451a6..cb3984dee 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -239,6 +239,7 @@ const struct __locale_t __C_locale =
};
#endif /* _MB_CAPABLE */
+#ifndef _REENT_SMALL
struct __locale_t __global_locale =
{
{ "C", "C", DEFAULT_LOCALE, "C", "C", "C", "C", },
@@ -278,6 +279,8 @@ struct __locale_t __global_locale =
},
#endif /* __HAVE_LOCALE_INFO__ */
};
+#endif /* !_REENT_SMALL */
+
#ifdef _MB_CAPABLE
/* Renamed from current_locale_string to make clear this is only the
@@ -288,6 +291,17 @@ static char *currentlocale (void);
#endif /* _MB_CAPABLE */
+#ifdef _REENT_SMALL
+const char *default_decimal_point = ".";
+
+const char *
+_locale_decimalpoint (void *locale)
+{
+ return default_decimal_point;
+}
+
+#endif
+
char *
_setlocale_r (struct _reent *p,
int category,
@@ -879,7 +893,7 @@ restart:
switch (category)
{
case LC_CTYPE:
-#ifndef __HAVE_LOCALE_INFO__
+#if !defined(__HAVE_LOCALE_INFO__) && !defined (_REENT_SMALL)
strcpy (loc->ctype_codeset, charset);
loc->mb_cur_max[0] = mbc_max;
#endif
@@ -964,6 +978,7 @@ __get_locale_env (struct _reent *p, int category)
}
#endif /* _MB_CAPABLE */
+#ifndef _REENT_SMALL
int
__locale_mb_cur_max (void)
{
@@ -973,17 +988,27 @@ __locale_mb_cur_max (void)
return __get_current_locale ()->mb_cur_max[0];
#endif
}
+#endif /* !_REENT_SMALL */
const char *
__locale_ctype_ptr_l (struct __locale_t *locale)
{
+#ifdef _REENT_SMALL
+ return DEFAULT_CTYPE_PTR;
+#else
return locale->ctype_ptr;
+#endif
+
}
const char *
__locale_ctype_ptr (void)
{
+#ifdef _REENT_SMALL
+ return DEFAULT_CTYPE_PTR;
+#else
return __get_current_locale ()->ctype_ptr;
+#endif
}
#ifndef _REENT_ONLY
diff --git a/newlib/libc/locale/localeconv.c b/newlib/libc/locale/localeconv.c
index 5f34a785f..ca132c5cd 100644
--- a/newlib/libc/locale/localeconv.c
+++ b/newlib/libc/locale/localeconv.c
@@ -2,6 +2,8 @@
#include <reent.h>
#include "setlocale.h"
+#ifndef _REENT_SMALL
+
struct lconv *
__localeconv_l (struct __locale_t *locale)
{
@@ -65,4 +67,8 @@ localeconv (void)
{
return __localeconv_l (__get_current_locale ());
}
+#endif /* _REENT_SMALL */
+
#endif
+
+
diff --git a/newlib/libc/locale/newlocale.c b/newlib/libc/locale/newlocale.c
index c6c2a9ca9..a696cbc0c 100644
--- a/newlib/libc/locale/newlocale.c
+++ b/newlib/libc/locale/newlocale.c
@@ -86,6 +86,10 @@ struct __locale_t *
_newlocale_r (struct _reent *p, int category_mask, const char *locale,
struct __locale_t *base)
{
+#ifdef _REENT_SMALL
+ p->_errno = ENOMEM;
+ return (locale_t)0;
+#else
#ifndef _MB_CAPABLE
return __get_C_locale ();
#else /* _MB_CAPABLE */
@@ -213,6 +217,7 @@ error:
return NULL;
#endif /* _MB_CAPABLE */
+#endif /* _REENT_SMALL */
}
struct __locale_t *
diff --git a/newlib/libc/locale/nl_langinfo.c b/newlib/libc/locale/nl_langinfo.c
index eb984912f..882dc77b6 100644
--- a/newlib/libc/locale/nl_langinfo.c
+++ b/newlib/libc/locale/nl_langinfo.c
@@ -331,6 +331,7 @@ do_codeset:
break;
case CRNCYSTR:
ret = "";
+#ifndef _REENT_SMALL
cs = (char*) __get_monetary_locale (locale)->currency_symbol;
if (*cs != '\0') {
char pos = __localeconv_l (locale)->p_cs_precedes;
@@ -360,6 +361,7 @@ do_codeset:
}
}
}
+#endif /* !_REENT_SMALL */
break;
case D_MD_ORDER: /* local extension */
ret = (char *) __get_time_locale (locale)->md_order;
@@ -370,6 +372,7 @@ do_codeset:
break;
#endif
default:
+#ifndef _REENT_SMALL
/* Relies on the fact that LC_ALL is 0, and all other
LC_ constants are in ascending order. */
if (item > NL_LOCALE_NAME(LC_ALL)
@@ -377,6 +380,7 @@ do_codeset:
return locale->categories[item
- NL_LOCALE_NAME(LC_ALL)];
}
+#endif
#ifdef __HAVE_LOCALE_INFO_EXTENDED__
if (item > _NL_LOCALE_EXTENDED_FIRST_ENTRY
&& item < _NL_LOCALE_EXTENDED_LAST_ENTRY) {
@@ -392,5 +396,9 @@ do_codeset:
char *nl_langinfo (nl_item item)
{
+#ifdef _REENT_SMALL
+ return nl_langinfo_l (item, NULL );
+#else
return nl_langinfo_l (item, __get_current_locale ());
+#endif
}
diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h
index fe212c1ec..f2621b0b1 100644
--- a/newlib/libc/locale/setlocale.h
+++ b/newlib/libc/locale/setlocale.h
@@ -199,11 +199,14 @@ extern char *__loadlocale (struct __locale_t *, int, const char *);
extern const char *__get_locale_env(struct _reent *, int);
#endif /* _MB_CAPABLE */
-extern struct lconv *__localeconv_l (struct __locale_t *locale);
-
extern size_t _wcsnrtombs_l (struct _reent *, char *, const wchar_t **,
size_t, size_t, mbstate_t *, struct __locale_t *);
+
+#ifndef _REENT_SMALL
+
+extern struct lconv *__localeconv_l (struct __locale_t *locale);
+
/* In POSIX terms the global locale is the process-wide locale. Use this
function to always refer to the global locale. */
_ELIDABLE_INLINE struct __locale_t *
@@ -257,6 +260,7 @@ __get_current_collate_locale (void)
__get_current_locale ()->lc_cat[LC_COLLATE].ptr;
}
#endif
+#endif /* !_REENT_SMALL */
#ifdef __HAVE_LOCALE_INFO__
_ELIDABLE_INLINE const struct lc_ctype_T *
@@ -276,14 +280,18 @@ __get_current_ctype_locale (void)
_ELIDABLE_INLINE int
__locale_mb_cur_max_l (struct __locale_t *locale)
{
+#ifdef _REENT_SMALL
+ return _MB_LEN_MAX;
+#else
#ifdef __HAVE_LOCALE_INFO__
return __get_ctype_locale (locale)->mb_cur_max[0];
#else
return locale->mb_cur_max[0];
#endif
+#endif
}
-#ifdef __HAVE_LOCALE_INFO__
+#if defined (__HAVE_LOCALE_INFO__) && !defined(_REENT_SMALL)
_ELIDABLE_INLINE const struct lc_monetary_T *
__get_monetary_locale (struct __locale_t *locale)
{
@@ -385,6 +393,7 @@ __get_current_messages_locale (void)
}
#endif /* !__HAVE_LOCALE_INFO__ */
+#ifndef _REENT_SMALL
_ELIDABLE_INLINE const char *
__locale_charset (struct __locale_t *locale)
{
@@ -438,14 +447,31 @@ int __collate_load_locale (struct __locale_t *, const char *, void *,
extern void __set_charset_from_locale (const char *locale, char *charset);
extern char *__set_locale_from_locale_alias (const char *, char *);
#endif
+#endif /* !_REENT_SMALL */
+#ifdef _REENT_SMALL
+const char *_locale_decimalpoint(void *locale);
+#define __CURRENT_LOCALE (locale_t)0
+#ifdef __CYGWIN__
+#define _locale_wctomb(loc,r,buff,wc,ps) __utf8_wctomb(r,buff,wc,ps)
+#define _locale_mbtowc(loc,r,buff,wc,ps) __utf8_mbtowc(r,buff,wc,ps)
+#define __WCTOMB __utf8_wctomb
+#define __MBTOWC __utf8_mbtowc
+#else
+#define _locale_wctomb(loc,r,buff,wc,ps) __ascii_wctomb(r,buff,wc,ps)
+#define _locale_mbtowc(loc,r,buff,wc,ps) __ascii_mbtowc(r,buff,wc,ps)
+#define __WCTOMB __ascii_wctomb
+#define __MBTOWC __ascii_mbtowc
+#endif /* __CYGWIN__ */
+#else /* _REENT_SMALL */
#define _locale_decimalpoint(loc) (__localeconv_l(loc))->decimal_point
#define _locale_wctomb(loc,r,buff,wc,ps) (loc)->wctomb(r,buff,wc,ps)
#define _locale_mbtowc(loc,r,buff,wc,ps) (loc)->mbtowc(r,buff,wc,ps)
#define __WCTOMB (__get_current_locale ()->wctomb)
#define __MBTOWC (__get_current_locale ()->mbtowc)
-
#define __CURRENT_LOCALE __get_current_locale()
+#endif /* _REENT_SMALL */
+
__END_DECLS
#endif /* !_SETLOCALE_H_ */
diff --git a/newlib/libc/locale/uselocale.c b/newlib/libc/locale/uselocale.c
index 83ebcdd19..a6eb197b5 100644
--- a/newlib/libc/locale/uselocale.c
+++ b/newlib/libc/locale/uselocale.c
@@ -51,6 +51,7 @@ PORTABILITY
*/
#include <newlib.h>
+#include <errno.h>
#include <reent.h>
#include <stdlib.h>
#include "setlocale.h"
@@ -58,6 +59,10 @@ PORTABILITY
struct __locale_t *
_uselocale_r (struct _reent *p, struct __locale_t *newloc)
{
+#ifdef _REENT_SMALL
+ p->_errno = ENOMEM;
+ return (locale_t)0;
+#else
struct __locale_t *current_locale;
current_locale = __get_locale_r (p);
@@ -68,6 +73,7 @@ _uselocale_r (struct _reent *p, struct __locale_t *newloc)
else if (newloc)
p->_locale = newloc;
return current_locale;
+#endif
}
#ifndef _REENT_ONLY
--
2.11.0
More information about the Newlib
mailing list