summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--newlib/libc/locale/lctype.c11
-rw-r--r--newlib/libc/locale/lctype.h48
-rw-r--r--newlib/libc/locale/lmessages.c11
-rw-r--r--newlib/libc/locale/lmessages.h58
-rw-r--r--newlib/libc/locale/lmonetary.c11
-rw-r--r--newlib/libc/locale/lmonetary.h77
-rw-r--r--newlib/libc/locale/lnumeric.c11
-rw-r--r--newlib/libc/locale/lnumeric.h55
-rw-r--r--newlib/libc/locale/locale.c25
-rw-r--r--newlib/libc/locale/nl_langinfo.c13
-rw-r--r--newlib/libc/locale/setlocale.h235
-rw-r--r--newlib/libc/locale/timelocal.c11
-rw-r--r--newlib/libc/locale/timelocal.h86
-rw-r--r--newlib/libc/stdio/vfwprintf.c2
-rw-r--r--newlib/libc/stdio/vfwscanf.c2
-rw-r--r--newlib/libc/time/strftime.c4
-rw-r--r--newlib/libc/time/strptime.c4
-rw-r--r--winsup/cygwin/libc/strptime.cc5
-rw-r--r--winsup/cygwin/nlsfuncs.cc72
-rw-r--r--winsup/cygwin/regex/regcomp.c8
20 files changed, 272 insertions, 477 deletions
diff --git a/newlib/libc/locale/lctype.c b/newlib/libc/locale/lctype.c
index a776ee09f..d59ae3734 100644
--- a/newlib/libc/locale/lctype.c
+++ b/newlib/libc/locale/lctype.c
@@ -28,7 +28,7 @@
static char numone[] = { '\1', '\0'};
-static const struct lc_ctype_T _C_ctype_locale = {
+const struct lc_ctype_T _C_ctype_locale = {
"ASCII", /* codeset */
numone /* mb_cur_max */
#ifdef __HAVE_LOCALE_INFO_EXTENDED__
@@ -77,7 +77,7 @@ __ctype_load_locale (struct _thr_locale_t *locale, const char *name,
return -1;
memcpy (ctp, &ct, sizeof *ctp);
}
- locale->ctype = ret == 0 ? NULL : ctp;
+ locale->ctype = ret == 0 ? &_C_ctype_locale : ctp;
if (locale->ctype_buf)
free (locale->ctype_buf);
locale->ctype_buf = bufp;
@@ -118,10 +118,3 @@ __ctype_load_locale (struct _thr_locale_t *locale, const char *name,
#endif
return ret;
}
-
-struct lc_ctype_T *
-__get_current_ctype_locale (void)
-{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->ctype ?: (struct lc_ctype_T *) &_C_ctype_locale;
-}
diff --git a/newlib/libc/locale/lctype.h b/newlib/libc/locale/lctype.h
deleted file mode 100644
index ead08c567..000000000
--- a/newlib/libc/locale/lctype.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef _LCTYPE_H_
-#define _LCTYPE_H_
-
-#include <_ansi.h>
-#include <sys/cdefs.h>
-#include <wchar.h>
-
-__BEGIN_DECLS
-
-struct lc_ctype_T {
- const char *codeset; /* codeset for mbtowc conversion */
- const char *mb_cur_max;
-#ifdef __HAVE_LOCALE_INFO_EXTENDED__
- const char *outdigits[10];
- const wchar_t *woutdigits[10];
-#endif
-};
-
-struct lc_ctype_T *__get_current_ctype_locale (void);
-int __ctype_load_locale (struct _thr_locale_t *, const char *, void *,
- const char *, int);
-
-__END_DECLS
-
-#endif /* !_LCTYPE_H_ */
diff --git a/newlib/libc/locale/lmessages.c b/newlib/libc/locale/lmessages.c
index 7d9096e6c..c768e4595 100644
--- a/newlib/libc/locale/lmessages.c
+++ b/newlib/libc/locale/lmessages.c
@@ -39,7 +39,7 @@
static char empty[] = "";
#endif
-static const struct lc_messages_T _C_messages_locale = {
+const struct lc_messages_T _C_messages_locale = {
"^[yY]" , /* yesexpr */
"^[nN]" , /* noexpr */
"yes" , /* yesstr */
@@ -87,7 +87,7 @@ __messages_load_locale (struct _thr_locale_t *locale, const char *name,
return -1;
memcpy (mep, &me, sizeof *mep);
}
- locale->messages = ret == 0 ? NULL : mep;
+ locale->messages = ret == 0 ? &_C_messages_locale : mep;
if (locale->messages_buf)
free (locale->messages_buf);
locale->messages_buf = bufp;
@@ -110,13 +110,6 @@ __messages_load_locale (struct _thr_locale_t *locale, const char *name,
return ret;
}
-struct lc_messages_T *
-__get_current_messages_locale (void)
-{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->messages ?: (struct lc_messages_T *) &_C_messages_locale;
-}
-
#ifdef LOCALE_DEBUG
void
msgdebug() {
diff --git a/newlib/libc/locale/lmessages.h b/newlib/libc/locale/lmessages.h
deleted file mode 100644
index 242a67ef9..000000000
--- a/newlib/libc/locale/lmessages.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/libc/locale/lmessages.h,v 1.3 2001/12/20 18:28:52 phantom Exp $
- */
-
-#ifndef _LMESSAGES_H_
-#define _LMESSAGES_H_
-
-#include <_ansi.h>
-#include <sys/cdefs.h>
-#include <wchar.h>
-
-__BEGIN_DECLS
-
-struct lc_messages_T {
- const char *yesexpr;
- const char *noexpr;
- const char *yesstr;
- const char *nostr;
-#ifdef __HAVE_LOCALE_INFO_EXTENDED__
- const char *codeset; /* codeset for mbtowc conversion */
- const wchar_t *wyesexpr;
- const wchar_t *wnoexpr;
- const wchar_t *wyesstr;
- const wchar_t *wnostr;
-#endif
-};
-
-struct lc_messages_T *__get_current_messages_locale (void);
-int __messages_load_locale (struct _thr_locale_t *, const char *, void *,
- const char *);
-
-__END_DECLS
-
-#endif /* !_LMESSAGES_H_ */
diff --git a/newlib/libc/locale/lmonetary.c b/newlib/libc/locale/lmonetary.c
index 344a6d81a..32e5ee525 100644
--- a/newlib/libc/locale/lmonetary.c
+++ b/newlib/libc/locale/lmonetary.c
@@ -41,7 +41,7 @@ static char numempty[] = { CHAR_MAX, '\0'};
static wchar_t wempty[] = L"";
#endif
-static const struct lc_monetary_T _C_monetary_locale = {
+const struct lc_monetary_T _C_monetary_locale = {
empty, /* int_curr_symbol */
empty, /* currency_symbol */
empty, /* mon_decimal_point */
@@ -115,7 +115,7 @@ __monetary_load_locale (struct _thr_locale_t *locale, const char *name ,
return -1;
memcpy (mop, &mo, sizeof *mop);
}
- locale->monetary = ret == 0 ? NULL : mop;
+ locale->monetary = ret == 0 ? &_C_monetary_locale : mop;
if (locale->monetary_buf)
free (locale->monetary_buf);
locale->monetary_buf = bufp;
@@ -145,10 +145,3 @@ __monetary_load_locale (struct _thr_locale_t *locale, const char *name ,
#endif
return ret;
}
-
-struct lc_monetary_T *
-__get_current_monetary_locale (void)
-{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->monetary ?: (struct lc_monetary_T *) &_C_monetary_locale;
-}
diff --git a/newlib/libc/locale/lmonetary.h b/newlib/libc/locale/lmonetary.h
deleted file mode 100644
index 98000d615..000000000
--- a/newlib/libc/locale/lmonetary.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/libc/locale/lmonetary.h,v 1.3 2001/12/20 18:28:52 phantom Exp $
- */
-
-#ifndef _LMONETARY_H_
-#define _LMONETARY_H_
-
-#include <_ansi.h>
-#include <sys/cdefs.h>
-#include <wchar.h>
-
-__BEGIN_DECLS
-
-struct lc_monetary_T {
- const char *int_curr_symbol;
- const char *currency_symbol;
- const char *mon_decimal_point;
- const char *mon_thousands_sep;
- const char *mon_grouping;
- const char *positive_sign;
- const char *negative_sign;
- const char *int_frac_digits;
- const char *frac_digits;
- const char *p_cs_precedes;
- const char *p_sep_by_space;
- const char *n_cs_precedes;
- const char *n_sep_by_space;
- const char *p_sign_posn;
- const char *n_sign_posn;
-#ifdef __HAVE_LOCALE_INFO_EXTENDED__
- const char *int_p_cs_precedes;
- const char *int_p_sep_by_space;
- const char *int_n_cs_precedes;
- const char *int_n_sep_by_space;
- const char *int_p_sign_posn;
- const char *int_n_sign_posn;
- const char *codeset; /* codeset for mbtowc conversion */
- const wchar_t *wint_curr_symbol;
- const wchar_t *wcurrency_symbol;
- const wchar_t *wmon_decimal_point;
- const wchar_t *wmon_thousands_sep;
- const wchar_t *wpositive_sign;
- const wchar_t *wnegative_sign;
-#endif
-};
-
-struct lc_monetary_T *__get_current_monetary_locale (void);
-int __monetary_load_locale (struct _thr_locale_t *, const char *, void *,
- const char *);
-
-__END_DECLS
-
-#endif /* !_LMONETARY_H_ */
diff --git a/newlib/libc/locale/lnumeric.c b/newlib/libc/locale/lnumeric.c
index f74c44612..0e56f1662 100644
--- a/newlib/libc/locale/lnumeric.c
+++ b/newlib/libc/locale/lnumeric.c
@@ -33,7 +33,7 @@ extern const char *__fix_locale_grouping_str(const char *);
static char numempty[] = { CHAR_MAX, '\0' };
-static const struct lc_numeric_T _C_numeric_locale = {
+const struct lc_numeric_T _C_numeric_locale = {
".", /* decimal_point */
"", /* thousands_sep */
numempty /* grouping */
@@ -77,7 +77,7 @@ __numeric_load_locale (struct _thr_locale_t *locale, const char *name ,
return -1;
memcpy (nmp, &nm, sizeof *nmp);
}
- locale->numeric = ret == 0 ? NULL : nmp;
+ locale->numeric = ret == 0 ? &_C_numeric_locale : nmp;
if (locale->numeric_buf)
free (locale->numeric_buf);
locale->numeric_buf = bufp;
@@ -94,10 +94,3 @@ __numeric_load_locale (struct _thr_locale_t *locale, const char *name ,
#endif
return ret;
}
-
-struct lc_numeric_T *
-__get_current_numeric_locale (void)
-{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->numeric ?: (struct lc_numeric_T *) &_C_numeric_locale;
-}
diff --git a/newlib/libc/locale/lnumeric.h b/newlib/libc/locale/lnumeric.h
deleted file mode 100644
index 8a41966b7..000000000
--- a/newlib/libc/locale/lnumeric.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * Copyright (c) 2000, 2001 Alexey Zelkin <phantom@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/libc/locale/lnumeric.h,v 1.3 2001/12/20 18:28:52 phantom Exp $
- */
-
-#ifndef _LNUMERIC_H_
-#define _LNUMERIC_H_
-
-#include <_ansi.h>
-#include <sys/cdefs.h>
-#include <wchar.h>
-
-__BEGIN_DECLS
-
-struct lc_numeric_T {
- const char *decimal_point;
- const char *thousands_sep;
- const char *grouping;
-#ifdef __HAVE_LOCALE_INFO_EXTENDED__
- const char *codeset; /* codeset for mbtowc conversion */
- const wchar_t *wdecimal_point;
- const wchar_t *wthousands_sep;
-#endif
-};
-
-struct lc_numeric_T *__get_current_numeric_locale (void);
-int __numeric_load_locale (struct _thr_locale_t *, const char *, void *,
- const char *);
-
-__END_DECLS
-
-#endif /* !_LNUMERIC_H_ */
diff --git a/newlib/libc/locale/locale.c b/newlib/libc/locale/locale.c
index 83d83a5ed..eb08dade5 100644
--- a/newlib/libc/locale/locale.c
+++ b/newlib/libc/locale/locale.c
@@ -236,24 +236,25 @@ struct _thr_locale_t __global_locale =
__ascii_wctomb,
__ascii_mbtowc,
#endif
- NULL,
0,
+ NULL,
#ifndef __HAVE_LOCALE_INFO__
"\1",
"ASCII",
"ASCII",
#else
+ &_C_ctype_locale,
NULL,
+ &_C_monetary_locale,
NULL,
+ &_C_numeric_locale,
NULL,
+ &_C_time_locale,
NULL,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
+ &_C_messages_locale,
NULL,
#ifdef __CYGWIN__
+ &_C_collate_locale,
NULL,
#endif
#endif
@@ -442,12 +443,6 @@ currentlocale()
#endif /* _MB_CAPABLE */
#ifdef _MB_CAPABLE
-#ifdef __CYGWIN__
-extern void __set_charset_from_locale (const char *locale, char *charset);
-extern char *__set_locale_from_locale_alias (const char *, char *);
-extern int __collate_load_locale (struct _thr_locale_t *, const char *, void *,
- const char *);
-#endif /* __CYGWIN__ */
extern void __set_ctype (struct _reent *, const char *charset);
@@ -952,7 +947,7 @@ char *
_DEFUN_VOID(__locale_charset)
{
#ifdef __HAVE_LOCALE_INFO__
- return (char *) __get_current_ctype_locale ()->codeset;
+ return __get_current_ctype_locale ()->codeset;
#else
return __global_locale.ctype_codeset;
#endif
@@ -1005,8 +1000,8 @@ _DEFUN(_localeconv_r, (data),
struct _reent *data)
{
#ifdef __HAVE_LOCALE_INFO__
- struct lc_numeric_T *n = __get_current_numeric_locale ();
- struct lc_monetary_T *m = __get_current_monetary_locale ();
+ const struct lc_numeric_T *n = __get_current_numeric_locale ();
+ const struct lc_monetary_T *m = __get_current_monetary_locale ();
lconv.decimal_point = (char *) n->decimal_point;
lconv.thousands_sep = (char *) n->thousands_sep;
diff --git a/newlib/libc/locale/nl_langinfo.c b/newlib/libc/locale/nl_langinfo.c
index 3acbc3a04..ce6d8d8c2 100644
--- a/newlib/libc/locale/nl_langinfo.c
+++ b/newlib/libc/locale/nl_langinfo.c
@@ -48,11 +48,11 @@
static struct _nl_item_t
{
union {
- struct lc_ctype_T * (*ctype)(void);
- struct lc_time_T * (*time)(void);
- struct lc_numeric_T * (*numeric)(void);
- struct lc_monetary_T * (*monetary)(void);
- struct lc_messages_T * (*messages)(void);
+ const struct lc_ctype_T * (*ctype)(void);
+ const struct lc_time_T * (*time)(void);
+ const struct lc_numeric_T * (*numeric)(void);
+ const struct lc_monetary_T * (*monetary)(void);
+ const struct lc_messages_T * (*messages)(void);
void * (*base)(void);
};
_off_t offset;
@@ -206,8 +206,7 @@ _DEFUN(nl_langinfo, (item),
#ifdef __CYGWIN__
case _NL_COLLATE_CODESET:
{
- extern const char *__get_current_collate_codeset (void);
- ret = (char *) __get_current_collate_codeset ();
+ ret = (char *) __get_current_collate_locale ()->codeset;
goto do_codeset;
}
#endif /* __CYGWIN__ */
diff --git a/newlib/libc/locale/setlocale.h b/newlib/libc/locale/setlocale.h
index a4b55a6c7..ffb1cf13e 100644
--- a/newlib/libc/locale/setlocale.h
+++ b/newlib/libc/locale/setlocale.h
@@ -29,59 +29,176 @@
#ifndef _SETLOCALE_H_
#define _SETLOCALE_H_
+#include <_ansi.h>
+#include <sys/cdefs.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
+#include <wchar.h>
#include <locale.h>
-#include "lctype.h"
-#include "lmessages.h"
-#include "lnumeric.h"
-#include "timelocal.h"
-#include "lmonetary.h"
+
+__BEGIN_DECLS
#define ENCODING_LEN 31
#define CATEGORY_LEN 11
#define _LC_LAST 7
+struct lc_ctype_T {
+ const char *codeset; /* codeset for mbtowc conversion */
+ const char *mb_cur_max;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *outdigits[10];
+ const wchar_t *woutdigits[10];
+#endif
+};
+extern const struct lc_ctype_T _C_ctype_locale;
+
+struct lc_monetary_T {
+ const char *int_curr_symbol;
+ const char *currency_symbol;
+ const char *mon_decimal_point;
+ const char *mon_thousands_sep;
+ const char *mon_grouping;
+ const char *positive_sign;
+ const char *negative_sign;
+ const char *int_frac_digits;
+ const char *frac_digits;
+ const char *p_cs_precedes;
+ const char *p_sep_by_space;
+ const char *n_cs_precedes;
+ const char *n_sep_by_space;
+ const char *p_sign_posn;
+ const char *n_sign_posn;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *int_p_cs_precedes;
+ const char *int_p_sep_by_space;
+ const char *int_n_cs_precedes;
+ const char *int_n_sep_by_space;
+ const char *int_p_sign_posn;
+ const char *int_n_sign_posn;
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wint_curr_symbol;
+ const wchar_t *wcurrency_symbol;
+ const wchar_t *wmon_decimal_point;
+ const wchar_t *wmon_thousands_sep;
+ const wchar_t *wpositive_sign;
+ const wchar_t *wnegative_sign;
+#endif
+};
+extern const struct lc_monetary_T _C_monetary_locale;
+
+struct lc_numeric_T {
+ const char *decimal_point;
+ const char *thousands_sep;
+ const char *grouping;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wdecimal_point;
+ const wchar_t *wthousands_sep;
+#endif
+};
+extern const struct lc_numeric_T _C_numeric_locale;
+
+struct lc_time_T {
+ const char *mon[12];
+ const char *month[12];
+ const char *wday[7];
+ const char *weekday[7];
+ const char *X_fmt;
+ const char *x_fmt;
+ const char *c_fmt;
+ const char *am_pm[2];
+ const char *date_fmt;
+ const char *alt_month[12]; /* unused */
+ const char *md_order;
+ const char *ampm_fmt;
+ const char *era;
+ const char *era_d_fmt;
+ const char *era_d_t_fmt;
+ const char *era_t_fmt;
+ const char *alt_digits;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wmon[12];
+ const wchar_t *wmonth[12];
+ const wchar_t *wwday[7];
+ const wchar_t *wweekday[7];
+ const wchar_t *wX_fmt;
+ const wchar_t *wx_fmt;
+ const wchar_t *wc_fmt;
+ const wchar_t *wam_pm[2];
+ const wchar_t *wdate_fmt;
+ const wchar_t *wampm_fmt;
+ const wchar_t *wera;
+ const wchar_t *wera_d_fmt;
+ const wchar_t *wera_d_t_fmt;
+ const wchar_t *wera_t_fmt;
+ const wchar_t *walt_digits;
+#endif
+};
+extern const struct lc_time_T _C_time_locale;
+
+struct lc_messages_T {
+ const char *yesexpr;
+ const char *noexpr;
+ const char *yesstr;
+ const char *nostr;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+ const char *codeset; /* codeset for mbtowc conversion */
+ const wchar_t *wyesexpr;
+ const wchar_t *wnoexpr;
+ const wchar_t *wyesstr;
+ const wchar_t *wnostr;
+#endif
+};
+extern const struct lc_messages_T _C_messages_locale;
+
#ifdef __CYGWIN__
-struct lc_collate_T;
+typedef __uint32_t LCID;
+
+struct lc_collate_T
+{
+ LCID lcid;
+ int (*mbtowc) (struct _reent *, wchar_t *, const char *, size_t, const char *,
+ mbstate_t *);
+ char codeset[ENCODING_LEN + 1];
+};
+extern const struct lc_collate_T _C_collate_locale;
#endif
struct _thr_locale_t
{
- char categories[_LC_LAST][ENCODING_LEN + 1];
- int (*__wctomb) (struct _reent *, char *, wchar_t,
- const char *, mbstate_t *);
- int (*__mbtowc) (struct _reent *, wchar_t *, const char *,
- size_t, const char *, mbstate_t *);
- char *ctype_ptr; /* Unused in __global_locale */
- int cjk_lang;
+ char categories[_LC_LAST][ENCODING_LEN + 1];
+ int (*__wctomb) (struct _reent *, char *, wchar_t,
+ const char *, mbstate_t *);
+ int (*__mbtowc) (struct _reent *, wchar_t *,
+ const char *, size_t, const char *,
+ mbstate_t *);
+ char *ctype_ptr; /* Unused in __global_locale */
+ int cjk_lang;
#ifndef __HAVE_LOCALE_INFO__
- char mb_cur_max[2];
- char ctype_codeset[ENCODING_LEN + 1];
- char message_codeset[ENCODING_LEN + 1];
+ char mb_cur_max[2];
+ char ctype_codeset[ENCODING_LEN + 1];
+ char message_codeset[ENCODING_LEN + 1];
#else
- struct lc_ctype_T *ctype;
- char *ctype_buf;
- struct lc_monetary_T *monetary;
- char *monetary_buf;
- struct lc_numeric_T *numeric;
- char *numeric_buf;
- struct lc_time_T *time;
- char *time_buf;
- struct lc_messages_T *messages;
- char *messages_buf;
+ const struct lc_ctype_T *ctype;
+ char *ctype_buf;
+ const struct lc_monetary_T *monetary;
+ char *monetary_buf;
+ const struct lc_numeric_T *numeric;
+ char *numeric_buf;
+ const struct lc_time_T *time;
+ char *time_buf;
+ const struct lc_messages_T *messages;
+ char *messages_buf;
#ifdef __CYGWIN__
- struct lc_collate_T *collate;
+ const struct lc_collate_T *collate;
+ char *collate_buf;
#endif
/* Append more categories here. */
#endif
};
-#ifdef __cplusplus
-extern "C" {
-#endif
-
extern struct _thr_locale_t __global_locale;
/* In POSIX terms the global locale is the process-wide locale. Use this
@@ -109,10 +226,64 @@ __get_current_locale ()
return _REENT->_locale ?: &__global_locale;
}
-#ifdef __cplusplus
+_ELIDABLE_INLINE const struct lc_ctype_T *
+__get_current_ctype_locale (void)
+{
+ return __get_current_locale ()->ctype;
+}
+
+_ELIDABLE_INLINE const struct lc_monetary_T *
+__get_current_monetary_locale (void)
+{
+ return __get_current_locale ()->monetary;
+}
+
+_ELIDABLE_INLINE const struct lc_time_T *
+__get_current_time_locale (void)
+{
+ return __get_current_locale ()->time;
+}
+
+_ELIDABLE_INLINE const struct lc_numeric_T *
+__get_current_numeric_locale (void)
+{
+ return __get_current_locale ()->numeric;
+}
+
+_ELIDABLE_INLINE const struct lc_messages_T *
+__get_current_messages_locale (void)
+{
+ return __get_current_locale ()->messages;
+}
+
+#ifdef __CYGWIN__
+_ELIDABLE_INLINE const struct lc_collate_T *
+__get_current_collate_locale (void)
+{
+ return __get_current_locale ()->collate;
}
#endif
+int __ctype_load_locale (struct _thr_locale_t *, const char *, void *,
+ const char *, int);
+int __monetary_load_locale (struct _thr_locale_t *, const char *, void *,
+ const char *);
+int __numeric_load_locale (struct _thr_locale_t *, const char *, void *,
+ const char *);
+int __time_load_locale (struct _thr_locale_t *, const char *, void *,
+ const char *);
+int __messages_load_locale (struct _thr_locale_t *, const char *, void *,
+ const char *);
+#ifdef __CYGWIN__
+int __collate_load_locale (struct _thr_locale_t *, const char *, void *,
+ const char *);
+
+extern void __set_charset_from_locale (const char *locale, char *charset);
+extern char *__set_locale_from_locale_alias (const char *, char *);
+#endif
+
extern char *_PathLocale;
+__END_DECLS
+
#endif /* !_SETLOCALE_H_ */
diff --git a/newlib/libc/locale/timelocal.c b/newlib/libc/locale/timelocal.c
index eda776a5b..5e64456ab 100644
--- a/newlib/libc/locale/timelocal.c
+++ b/newlib/libc/locale/timelocal.c
@@ -34,7 +34,7 @@
#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
-static const struct lc_time_T _C_time_locale = {
+const struct lc_time_T _C_time_locale = {
{
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
@@ -177,7 +177,7 @@ __time_load_locale (struct _thr_locale_t *locale, const char *name,
return -1;
memcpy (tip, &ti, sizeof *tip);
}
- locale->time = ret == 0 ? NULL : tip;
+ locale->time = ret == 0 ? &_C_time_locale : tip;
if (locale->time_buf)
free (locale->time_buf);
locale->time_buf = bufp;
@@ -191,10 +191,3 @@ __time_load_locale (struct _thr_locale_t *locale, const char *name,
#endif
return (ret);
}
-
-struct lc_time_T *
-__get_current_time_locale (void)
-{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->time ?: (struct lc_time_T *) &_C_time_locale;
-}
diff --git a/newlib/libc/locale/timelocal.h b/newlib/libc/locale/timelocal.h
deleted file mode 100644
index 6004ad88b..000000000
--- a/newlib/libc/locale/timelocal.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*-
- * Copyright (c) 1997-2002 FreeBSD Project.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD: src/lib/libc/stdtime/timelocal.h,v 1.11 2002/01/24 15:07:44 phantom Exp $
- */
-
-#ifndef _TIMELOCAL_H_
-#define _TIMELOCAL_H_
-
-#include <_ansi.h>
-#include <sys/cdefs.h>
-#include <wchar.h>
-
-__BEGIN_DECLS
-
-/*
- * Private header file for the strftime and strptime localization
- * stuff.
- */
-struct lc_time_T {
- const char *mon[12];
- const char *month[12];
- const char *wday[7];
- const char *weekday[7];
- const char *X_fmt;
- const char *x_fmt;
- const char *c_fmt;
- const char *am_pm[2];
- const char *date_fmt;
- const char *alt_month[12]; /* unused */
- const char *md_order;
- const char *ampm_fmt;
- const char *era;
- const char *era_d_fmt;
- const char *era_d_t_fmt;
- const char *era_t_fmt;
- const char *alt_digits;
-#ifdef __HAVE_LOCALE_INFO_EXTENDED__
- const char *codeset; /* codeset for mbtowc conversion */
- const wchar_t *wmon[12];
- const wchar_t *wmonth[12];
- const wchar_t *wwday[7];
- const wchar_t *wweekday[7];
- const wchar_t *wX_fmt;
- const wchar_t *wx_fmt;
- const wchar_t *wc_fmt;
- const wchar_t *wam_pm[2];
- const wchar_t *wdate_fmt;
- const wchar_t *wampm_fmt;
- const wchar_t *wera;
- const wchar_t *wera_d_fmt;
- const wchar_t *wera_d_t_fmt;
- const wchar_t *wera_t_fmt;
- const wchar_t *walt_digits;
-#endif
-};
-
-struct lc_time_T *__get_current_time_locale (void);
-int __time_load_locale (struct _thr_locale_t *, const char *, void *,
- const char *);
-
-__END_DECLS
-
-#endif /* !_TIMELOCAL_H_ */
diff --git a/newlib/libc/stdio/vfwprintf.c b/newlib/libc/stdio/vfwprintf.c
index c3b8b27bb..f0179a014 100644
--- a/newlib/libc/stdio/vfwprintf.c
+++ b/newlib/libc/stdio/vfwprintf.c
@@ -132,7 +132,7 @@ SEEALSO
#include "fvwrite.h"
#include "vfieeefp.h"
#ifdef __HAVE_LOCALE_INFO_EXTENDED__
-#include "../locale/lnumeric.h"
+#include "../locale/setlocale.h"
#endif
/* Currently a test is made to see if long double processing is warranted.
diff --git a/newlib/libc/stdio/vfwscanf.c b/newlib/libc/stdio/vfwscanf.c
index 38a060d28..a46f8dcde 100644
--- a/newlib/libc/stdio/vfwscanf.c
+++ b/newlib/libc/stdio/vfwscanf.c
@@ -163,7 +163,7 @@ C99, POSIX-1.2008
#include <float.h>
#include <locale.h>
#ifdef __HAVE_LOCALE_INFO_EXTENDED__
-#include "../locale/lnumeric.h"
+#include "../locale/setlocale.h"
#endif
/* Currently a test is made to see if long double processing is warranted.
diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c
index ced106a5b..12c37ebea 100644
--- a/newlib/libc/time/strftime.c
+++ b/newlib/libc/time/strftime.c
@@ -276,7 +276,7 @@ the "C" locale settings.
#include <ctype.h>
#include <wctype.h>
#include "local.h"
-#include "../locale/timelocal.h"
+#include "../locale/setlocale.h"
/* Defines to make the file dual use for either strftime() or wcsftime().
* To get wcsftime, define MAKE_WCSFTIME.
@@ -709,7 +709,7 @@ _DEFUN (strftime, (s, maxsize, format, tim_p),
unsigned long width;
int tzset_called = 0;
- struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale ();
+ const struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale ();
for (;;)
{
while (*format && *format != CQ('%'))
diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c
index 19b9fcede..88b897834 100644
--- a/newlib/libc/time/strptime.c
+++ b/newlib/libc/time/strptime.c
@@ -37,7 +37,7 @@
#include <strings.h>
#include <ctype.h>
#include <stdlib.h>
-#include "../locale/timelocal.h"
+#include "../locale/setlocale.h"
#define _ctloc(x) (_CurrentTimeLocale->x)
@@ -160,7 +160,7 @@ _DEFUN (strptime, (buf, format, timeptr),
char c;
int ymd = 0;
- struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale ();
+ const struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale ();
for (; (c = *format) != '\0'; ++format) {
char *s;
int ret;
diff --git a/winsup/cygwin/libc/strptime.cc b/winsup/cygwin/libc/strptime.cc
index ad4d66150..c2bf17be7 100644
--- a/winsup/cygwin/libc/strptime.cc
+++ b/winsup/cygwin/libc/strptime.cc
@@ -46,7 +46,7 @@ __RCSID("$NetBSD: strptime.c,v 1.28 2008/04/28 20:23:01 martin Exp $");
#include <string.h>
#include <time.h>
#include <tzfile.h>
-#include "../locale/timelocal.h"
+#include "../locale/setlocale.h"
#ifdef __TM_GMTOFF
# define TM_GMTOFF __TM_GMTOFF
@@ -323,7 +323,8 @@ __strptime(const char *buf, const char *fmt, struct tm *tm,
int ymd = 0;
bp = (const unsigned char *)buf;
- struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale ();
+ const struct lc_time_T *_CurrentTimeLocale =
+ __get_current_time_locale ();
while (bp != NULL && (c = *fmt++) != '\0') {
/* Clear `alternate' modifier prior to new conversion. */
diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc
index 79ab3d1f5..6dde25111 100644
--- a/winsup/cygwin/nlsfuncs.cc
+++ b/winsup/cygwin/nlsfuncs.cc
@@ -1075,56 +1075,48 @@ __set_lc_messages_from_win (const char *name,
return 1;
}
-struct lc_collate_T
-{
- LCID lcid;
- mbtowc_p mbtowc;
- char codeset[ENCODING_LEN + 1];
-};
-
/* Called from newlib's setlocale() if category is LC_COLLATE. Stores
LC_COLLATE locale information. This is subsequently accessed by the
below functions strcoll, strxfrm, wcscoll, wcsxfrm. */
extern "C" int
__collate_load_locale (struct _thr_locale_t *locale, const char *name,
- mbtowc_p f_mbtowc, const char *charset)
+ void *f_mbtowc, const char *charset)
{
+ const struct lc_collate_T *ccop;
+ char *buf = NULL;
+
LCID lcid = __get_lcid_from_locale (name);
if (lcid == (LCID) -1)
return -1;
- struct lc_collate_T *cop;
- if (lcid)
+ if (!lcid)
+ {
+ ccop = &_C_collate_locale;
+ buf = NULL;
+ }
+ else
{
- cop = (struct lc_collate_T *) calloc (1, sizeof *cop);
- if (!cop)
+ buf = (char *) calloc (1, sizeof (struct lc_collate_T));
+ if (!buf)
return -1;
+ struct lc_collate_T *cop = (struct lc_collate_T *) buf;
cop->lcid = lcid;
- cop->mbtowc = f_mbtowc;
+ cop->mbtowc = (mbtowc_p) f_mbtowc;
stpcpy (cop->codeset, charset);
+ ccop = (const struct lc_collate_T *) cop;
}
+ locale->collate = ccop;
+ if (locale->collate_buf)
+ free (locale->collate_buf);
+ locale->collate_buf = buf;
return 0;
}
-extern "C" LCID
-__get_current_collate_lcid ()
+const struct lc_collate_T _C_collate_locale =
{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->collate ? cur_locale->collate->lcid : 0;
-}
-
-extern "C" const char *
-__get_current_collate_codeset (void)
-{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->collate ? cur_locale->collate->codeset : "ASCII";
-}
-
-static mbtowc_p
-__get_current_collate_mbtowc ()
-{
- struct _thr_locale_t *cur_locale = __get_current_locale ();
- return cur_locale->collate ? cur_locale->collate->mbtowc : __ascii_mbtowc;
-}
+ 0,
+ __ascii_mbtowc,
+ "ASCII"
+};
/* We use the Windows functions for locale-specific string comparison and
transformation. The advantage is that we don't need any files with
@@ -1133,7 +1125,7 @@ extern "C" int
wcscoll (const wchar_t *__restrict ws1, const wchar_t *__restrict ws2)
{
int ret;
- LCID collate_lcid = __get_current_collate_lcid ();
+ LCID collate_lcid = __get_current_collate_locale ()->lcid;
if (!collate_lcid)
return wcscmp (ws1, ws2);
@@ -1150,14 +1142,14 @@ strcoll (const char *__restrict s1, const char *__restrict s2)
wchar_t *ws1, *ws2;
tmp_pathbuf tp;
int ret;
- LCID collate_lcid = __get_current_collate_lcid ();
+ LCID collate_lcid = __get_current_collate_locale ()->lcid;
if (!collate_lcid)
return strcmp (s1, s2);
/* The ANSI version of CompareString uses the default charset of the lcid,
so we must use the Unicode version. */
- mbtowc_p collate_mbtowc = __get_current_collate_mbtowc ();
- const char *collate_charset = __get_current_collate_codeset ();
+ mbtowc_p collate_mbtowc = __get_current_collate_locale ()->mbtowc;
+ const char *collate_charset = __get_current_collate_locale ()->codeset;
n1 = lc_mbstowcs (collate_mbtowc, collate_charset, NULL, s1, 0) + 1;
ws1 = (n1 > NT_MAX_PATH ? (wchar_t *) malloc (n1 * sizeof (wchar_t))
: tp.w_get ());
@@ -1191,7 +1183,7 @@ extern "C" size_t
wcsxfrm (wchar_t *__restrict ws1, const wchar_t *__restrict ws2, size_t wsn)
{
size_t ret;
- LCID collate_lcid = __get_current_collate_lcid ();
+ LCID collate_lcid = __get_current_collate_locale ()->lcid;
if (!collate_lcid)
return wcslcpy (ws1, ws2, wsn);
@@ -1227,14 +1219,14 @@ strxfrm (char *__restrict s1, const char *__restrict s2, size_t sn)
size_t n2;
wchar_t *ws2;
tmp_pathbuf tp;
- LCID collate_lcid = __get_current_collate_lcid ();
+ LCID collate_lcid = __get_current_collate_locale ()->lcid;
if (!collate_lcid)
return strlcpy (s1, s2, sn);
/* The ANSI version of LCMapString uses the default charset of the lcid,
so we must use the Unicode version. */
- mbtowc_p collate_mbtowc = __get_current_collate_mbtowc ();
- const char *collate_charset = __get_current_collate_codeset ();
+ mbtowc_p collate_mbtowc = __get_current_collate_locale ()->mbtowc;
+ const char *collate_charset = __get_current_collate_locale ()->codeset;
n2 = lc_mbstowcs (collate_mbtowc, collate_charset, NULL, s2, 0) + 1;
ws2 = (n2 > NT_MAX_PATH ? (wchar_t *) malloc (n2 * sizeof (wchar_t))
: tp.w_get ());
diff --git a/winsup/cygwin/regex/regcomp.c b/winsup/cygwin/regex/regcomp.c
index 50d5dad6d..0dc59ffcc 100644
--- a/winsup/cygwin/regex/regcomp.c
+++ b/winsup/cygwin/regex/regcomp.c
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD: src/lib/libc/regex/regcomp.c,v 1.36 2007/06/11 03:05:54 delp
#ifdef __CYGWIN__
#include "winsup.h"
+#include "../locale/setlocale.h"
#endif
#include <sys/types.h>
#include <stdio.h>
@@ -62,11 +63,6 @@ __FBSDID("$FreeBSD: src/lib/libc/regex/regcomp.c,v 1.36 2007/06/11 03:05:54 delp
#include "cname.h"
-#ifdef __CYGWIN__
-/* Defined in nlsfuncs.cc. */
-extern LCID __get_current_collate_lcid ();
-#endif
-
/*
* parse structure, passed up and down to avoid global variables and
* other clumsinesses
@@ -831,7 +827,7 @@ p_b_term(struct parse *p, cset *cs)
CHadd(p, cs, start);
else {
#ifdef __CYGWIN__
- if (!__get_current_collate_lcid ()) {
+ if (!__get_current_collate_locale ()->lcid) {
#else
if (__collate_load_error) {
#endif