This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: codeset problems in wprintf and wcsftime


On Feb 25 10:25, Corinna Vinschen wrote:
> - Add another flag __HAVE_WCHAR_LOCALE_INFO__ or something.  Used in
>   vfwprintf and wcsftime it would use different code for targets
>   which only have the multibyte locale info and targets which have
>   also the wide char representation.

Attached is a patch which does that and more.  I do not intend to apply
this patch before the next Cygwin release 1.7.2 is out (which will be
RSN), but I wanted to show what I have, so you guys can make a sanity
check on the new code if you're interested in this stuff.

Here's what the patch does, in random order:

- Add a new macro called __HAVE_LOCALE_INFO_EXTENDED__ which guards
  (almost) all of the new locale definitions.

- Add two files locale/lctype.[ch], which define a basic LC_CTYPE
  datastructure and functions as in the other categories.

  This adds two features.  One of them is for all targets.

  - The global variables lc_ctype_charset, __mb_cur_max, and
    lc_message_charset are no longer used on targets defining
    __HAVE_LOCALE_INFO__.  The reason is that global variables disallow
    to define thread-local locales.  These are a GNU extension which
    have been added to the latest POSIX-1.2008 standard, see
    uselocale(3).

    The replacement are codeset and mb_cur_max members in the LC_CTYPE
    structure, and codeset in the LC_MESSAGES structure.

    This affects especially the MB_CUR_MAX definition in stdlib.h.  It's
    not any longer just __mb_cur_max, rather it calls the new
    __locale_mb_cur_max() function.

  - The other feature is the definition of the "outdigits" LC_CTYPE
    members.  In glibc they are used in printf when specifying the "I"
    modifier in decimal numerical formats.  This is something I plan to
    add to printf (and a similar patch to scanf) at one point.

- Extend the other categories, LC_TIME, LC_MESSAGES, LC_NUMERIC, and
  LC_MONETARY, so that the extended datastructures hold at least
  additional wide char representations of the multibyte strings in the
  category, as well as the category codeset.

  The LC_MONETARY structure defines the additional int_* members
  required by POSIX, and the _localeconv_r() function in locale.c
  fetches the information according to the __HAVE_LOCALE_INFO_EXTENDED__
  definition.

- In langinfo.h, add an enum to enumerate new nl_items for the call to
  nl_langinfo.  This is how all members on all locale categories are
  accessed in glibc as well.  The names of the items is equivalent to
  the names used in glibc.

- nl_langinfo() handles all the new nl_items so they can be used in
  tools like locale(1).

- vwfprintf() does not any longer convert decimal_point and
  thousands_sep from multibyte to widechar if __HAVE_LOCALE_INFO_EXTENDED__
  is defined.  Rather it uses the widechar members directly.

- Same for the entire LC_TIME information in wcsftime().

I have a complementary Cygwin patch which already uses the new features
and provides full __HAVE_LOCALE_INFO_EXTENDED__ information in the
locale category structures.  Same for Cygwin's locale(1) tool.  I can
provide the patches as well, if anybody is interested.

Ok, since this patch is only for information and discussion for now,
I use the opportunity to omit the ChangeLog :)


Corinna


Index: libc/include/langinfo.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/langinfo.h,v
retrieving revision 1.2
diff -u -p -r1.2 langinfo.h
--- libc/include/langinfo.h	22 Feb 2010 10:53:04 -0000	1.2
+++ libc/include/langinfo.h	2 Mar 2010 20:33:47 -0000
@@ -29,113 +29,285 @@
 #ifndef _LANGINFO_H_
 #define	_LANGINFO_H_
 
+#include <newlib.h>
+#include <sys/config.h>
 #include <sys/cdefs.h>
 
 typedef int nl_item;
 
-/* Extract the category and item index from a constructed `nl_item' value.  */
-#define _NL_ITEM_CATEGORY(item)		((int) (item) >> 16)
-#define _NL_ITEM_INDEX(item)		((int) (item) & 0xffff)
-
-#define	CODESET		0	/* codeset name */
-#define	D_T_FMT		1	/* string for formatting date and time */
-#define	D_FMT		2	/* date format string */
-#define	T_FMT		3	/* time format string */
-#define	T_FMT_AMPM	4	/* a.m. or p.m. time formatting string */
-#define	AM_STR		5	/* Ante Meridian affix */
-#define	PM_STR		6	/* Post Meridian affix */
+enum __nl_item
+{
+  /* POSIX and BSD defined items have to be stick to the orignal values
+     to maintain backward compatibility. */
+  _NL_CTYPE_CODESET_NAME = 0,	/* codeset name */
+#define CODESET _NL_CTYPE_CODESET_NAME
+  D_T_FMT,			/* string for formatting date and time */
+#define D_T_FMT D_T_FMT
+  D_FMT,			/* date format string */
+#define D_FMT D_FMT
+  T_FMT,			/* time format string */
+#define T_FMT T_FMT
+  T_FMT_AMPM,			/* a.m. or p.m. time formatting string */
+#define T_FMT_AMPM T_FMT_AMPM
+  AM_STR,			/* Ante Meridian affix */
+#define AM_STR AM_STR
+  PM_STR,			/* Post Meridian affix */
+#define PM_STR PM_STR
 
 /* week day names */
-#define	DAY_1		7
-#define	DAY_2		8
-#define	DAY_3		9
-#define	DAY_4		10
-#define	DAY_5		11
-#define	DAY_6		12
-#define	DAY_7		13
+  DAY_1,
+#define DAY_1 DAY_1
+  DAY_2,
+#define DAY_2 DAY_2
+  DAY_3,
+#define DAY_3 DAY_3
+  DAY_4,
+#define DAY_4 DAY_4
+  DAY_5,
+#define DAY_5 DAY_5
+  DAY_6,
+#define DAY_6 DAY_6
+  DAY_7,
+#define DAY_7 DAY_7
 
 /* abbreviated week day names */
-#define	ABDAY_1		14
-#define	ABDAY_2		15
-#define	ABDAY_3		16
-#define	ABDAY_4		17
-#define	ABDAY_5		18
-#define	ABDAY_6		19
-#define	ABDAY_7		20
+  ABDAY_1,
+#define ABDAY_1 ABDAY_1
+  ABDAY_2,
+#define ABDAY_2 ABDAY_2
+  ABDAY_3,
+#define ABDAY_3 ABDAY_3
+  ABDAY_4,
+#define ABDAY_4 ABDAY_4
+  ABDAY_5,
+#define ABDAY_5 ABDAY_5
+  ABDAY_6,
+#define ABDAY_6 ABDAY_6
+  ABDAY_7,
+#define ABDAY_7 ABDAY_7
 
 /* month names */
-#define	MON_1		21
-#define	MON_2		22
-#define	MON_3		23
-#define	MON_4		24
-#define	MON_5		25
-#define	MON_6		26
-#define	MON_7		27
-#define	MON_8		28
-#define	MON_9		29
-#define	MON_10		30
-#define	MON_11		31
-#define	MON_12		32
+  MON_1,
+#define MON_1 MON_1
+  MON_2,
+#define MON_2 MON_2
+  MON_3,
+#define MON_3 MON_3
+  MON_4,
+#define MON_4 MON_4
+  MON_5,
+#define MON_5 MON_5
+  MON_6,
+#define MON_6 MON_6
+  MON_7,
+#define MON_7 MON_7
+  MON_8,
+#define MON_8 MON_8
+  MON_9,
+#define MON_9 MON_9
+  MON_10,
+#define MON_10 MON_10
+  MON_11,
+#define MON_11 MON_11
+  MON_12,
+#define MON_12 MON_12
 
 /* abbreviated month names */
-#define	ABMON_1		33
-#define	ABMON_2		34
-#define	ABMON_3		35
-#define	ABMON_4		36
-#define	ABMON_5		37
-#define	ABMON_6		38
-#define	ABMON_7		39
-#define	ABMON_8		40
-#define	ABMON_9		41
-#define	ABMON_10	42
-#define	ABMON_11	43
-#define	ABMON_12	44
-
-#define	ERA		45	/* era description segments */
-#define	ERA_D_FMT	46	/* era date format string */
-#define	ERA_D_T_FMT	47	/* era date and time format string */
-#define	ERA_T_FMT	48	/* era time format string */
-#define	ALT_DIGITS	49	/* alternative symbols for digits */
-
-#define	RADIXCHAR	50	/* radix char */
-#define	THOUSEP		51	/* separator for thousands */
-
-#define	YESEXPR		52	/* affirmative response expression */
-#define	NOEXPR		53	/* negative response expression */
-#define	YESSTR		54	/* affirmative response for yes/no queries */
-#define	NOSTR		55	/* negative response for yes/no queries */
-
-#define	CRNCYSTR	56	/* currency symbol */
-
-#define	D_MD_ORDER	57	/* month/day order (local extension) */
-
-#define _NL_CTYPE_TRANSLIT_TAB_SIZE 58
-#define _NL_CTYPE_TRANSLIT_FROM_IDX 59
-#define _NL_CTYPE_TRANSLIT_FROM_TBL 60
-#define _NL_CTYPE_TRANSLIT_TO_IDX 61
-#define _NL_CTYPE_TRANSLIT_TO_TBL 62
-#define _NL_CTYPE_TRANSLIT_DEFAULT_MISSING_LEN 63
-#define _NL_CTYPE_TRANSLIT_DEFAULT_MISSING 64
-#define _NL_CTYPE_TRANSLIT_IGNORE_LEN 65
-#define _NL_CTYPE_TRANSLIT_IGNORE 66
-#define _NL_CTYPE_EXTRA_MAP_1 70
-#define _NL_CTYPE_EXTRA_MAP_2 71
-#define _NL_CTYPE_EXTRA_MAP_3 72
-#define _NL_CTYPE_EXTRA_MAP_4 73
-#define _NL_CTYPE_EXTRA_MAP_5 74
-#define _NL_CTYPE_EXTRA_MAP_6 75
-#define _NL_CTYPE_EXTRA_MAP_7 76
-#define _NL_CTYPE_EXTRA_MAP_8 77
-#define _NL_CTYPE_EXTRA_MAP_9 78
-#define _NL_CTYPE_EXTRA_MAP_10 79
-#define _NL_CTYPE_EXTRA_MAP_11 80
-#define _NL_CTYPE_EXTRA_MAP_12 81
-#define _NL_CTYPE_EXTRA_MAP_13 82
-#define _NL_CTYPE_EXTRA_MAP_14 83
+  ABMON_1,
+#define ABMON_1 ABMON_1
+  ABMON_2,
+#define ABMON_2 ABMON_2
+  ABMON_3,
+#define ABMON_3 ABMON_3
+  ABMON_4,
+#define ABMON_4 ABMON_4
+  ABMON_5,
+#define ABMON_5 ABMON_5
+  ABMON_6,
+#define ABMON_6 ABMON_6
+  ABMON_7,
+#define ABMON_7 ABMON_7
+  ABMON_8,
+#define ABMON_8 ABMON_8
+  ABMON_9,
+#define ABMON_9 ABMON_9
+  ABMON_10,
+#define ABMON_10 ABMON_10
+  ABMON_11,
+#define ABMON_11 ABMON_11
+  ABMON_12,
+#define ABMON_12 ABMON_12
+
+  ERA,				/* era description segments */
+#define ERA ERA
+  ERA_D_FMT,			/* era date format string */
+#define ERA_D_FMT ERA_D_FMT
+  ERA_D_T_FMT,			/* era date and time format string */
+#define ERA_D_T_FMT ERA_D_T_FMT
+  ERA_T_FMT,			/* era time format string */
+#define ERA_T_FMT ERA_T_FMT
+  ALT_DIGITS,			/* alternative symbols for digits */
+#define ALT_DIGITS ALT_DIGITS
+
+  RADIXCHAR,			/* radix char */
+#define RADIXCHAR RADIXCHAR
+  THOUSEP,			/* separator for thousands */
+#define THOUSEP THOUSEP
+
+  YESEXPR,			/* affirmative response expression */
+#define YESEXPR YESEXPR
+  NOEXPR,			/* negative response expression */
+#define NOEXPR NOEXPR
+  YESSTR,			/* affirmative response for yes/no queries */
+#define YESSTR YESSTR
+  NOSTR,			/* negative response for yes/no queries */
+#define NOSTR NOSTR
 
-#define _NL_TIME_DATE_FMT 84
+  CRNCYSTR,			/* currency symbol */
+#define CRNCYSTR CRNCYSTR
+
+  D_MD_ORDER,			/* month/day order (BSD extension) */
+#define D_MD_ORDER D_MD_ORDER
+
+  _NL_TIME_DATE_FMT = 84,	/* date fmt used by date(1) (GNU extension) */
 #define _DATE_FMT _NL_TIME_DATE_FMT
 
+#ifdef __HAVE_LOCALE_INFO__
+  _NL_CTYPE_MB_CUR_MAX,
+  _NL_MESSAGES_CODESET,
+
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+
+  /* NOTE:
+  
+     Always maintain the order and position of existing entries!
+     Always append new entry to the list, prior to the definition
+     of _NL_LOCALE_EXTENDED_LAST_ENTRY. */
+
+  _NL_LOCALE_EXTENDED_FIRST_ENTRY,
+
+  _NL_CTYPE_OUTDIGITS0_MB,
+  _NL_CTYPE_OUTDIGITS1_MB,
+  _NL_CTYPE_OUTDIGITS2_MB,
+  _NL_CTYPE_OUTDIGITS3_MB,
+  _NL_CTYPE_OUTDIGITS4_MB,
+  _NL_CTYPE_OUTDIGITS5_MB,
+  _NL_CTYPE_OUTDIGITS6_MB,
+  _NL_CTYPE_OUTDIGITS7_MB,
+  _NL_CTYPE_OUTDIGITS8_MB,
+  _NL_CTYPE_OUTDIGITS9_MB,
+  _NL_CTYPE_OUTDIGITS0_WC,
+  _NL_CTYPE_OUTDIGITS1_WC,
+  _NL_CTYPE_OUTDIGITS2_WC,
+  _NL_CTYPE_OUTDIGITS3_WC,
+  _NL_CTYPE_OUTDIGITS4_WC,
+  _NL_CTYPE_OUTDIGITS5_WC,
+  _NL_CTYPE_OUTDIGITS6_WC,
+  _NL_CTYPE_OUTDIGITS7_WC,
+  _NL_CTYPE_OUTDIGITS8_WC,
+  _NL_CTYPE_OUTDIGITS9_WC,
+
+  _NL_TIME_CODESET,
+  _NL_TIME_WMON_1,
+  _NL_TIME_WMON_2,
+  _NL_TIME_WMON_3,
+  _NL_TIME_WMON_4,
+  _NL_TIME_WMON_5,
+  _NL_TIME_WMON_6,
+  _NL_TIME_WMON_7,
+  _NL_TIME_WMON_8,
+  _NL_TIME_WMON_9,
+  _NL_TIME_WMON_10,
+  _NL_TIME_WMON_11,
+  _NL_TIME_WMON_12,
+  _NL_TIME_WMONTH_1,
+  _NL_TIME_WMONTH_2,
+  _NL_TIME_WMONTH_3,
+  _NL_TIME_WMONTH_4,
+  _NL_TIME_WMONTH_5,
+  _NL_TIME_WMONTH_6,
+  _NL_TIME_WMONTH_7,
+  _NL_TIME_WMONTH_8,
+  _NL_TIME_WMONTH_9,
+  _NL_TIME_WMONTH_10,
+  _NL_TIME_WMONTH_11,
+  _NL_TIME_WMONTH_12,
+  _NL_TIME_WWDAY_1,
+  _NL_TIME_WWDAY_2,
+  _NL_TIME_WWDAY_3,
+  _NL_TIME_WWDAY_4,
+  _NL_TIME_WWDAY_5,
+  _NL_TIME_WWDAY_6,
+  _NL_TIME_WWDAY_7,
+  _NL_TIME_WWEEKDAY_1,
+  _NL_TIME_WWEEKDAY_2,
+  _NL_TIME_WWEEKDAY_3,
+  _NL_TIME_WWEEKDAY_4,
+  _NL_TIME_WWEEKDAY_5,
+  _NL_TIME_WWEEKDAY_6,
+  _NL_TIME_WWEEKDAY_7,
+  _NL_TIME_WT_FMT,
+  _NL_TIME_WD_FMT,
+  _NL_TIME_WD_T_FMT,
+  _NL_TIME_WAM_STR,
+  _NL_TIME_WPM_STR,
+  _NL_TIME_WDATE_FMT,
+  _NL_TIME_WT_FMT_AMPM,
+  _NL_TIME_WERA,
+  _NL_TIME_WERA_D_FMT,
+  _NL_TIME_WERA_D_T_FMT,
+  _NL_TIME_WERA_T_FMT,
+  _NL_TIME_WALT_DIGITS,
+
+  _NL_NUMERIC_CODESET,
+  _NL_NUMERIC_GROUPING,
+  _NL_NUMERIC_DECIMAL_POINT_WC,
+  _NL_NUMERIC_THOUSANDS_SEP_WC,
+
+  _NL_MONETARY_INT_CURR_SYMBOL,
+  _NL_MONETARY_CURRENCY_SYMBOL,
+  _NL_MONETARY_MON_DECIMAL_POINT,
+  _NL_MONETARY_MON_THOUSANDS_SEP,
+  _NL_MONETARY_MON_GROUPING,
+  _NL_MONETARY_POSITIVE_SIGN,
+  _NL_MONETARY_NEGATIVE_SIGN,
+  _NL_MONETARY_INT_FRAC_DIGITS,
+  _NL_MONETARY_FRAC_DIGITS,
+  _NL_MONETARY_P_CS_PRECEDES,
+  _NL_MONETARY_P_SEP_BY_SPACE,
+  _NL_MONETARY_N_CS_PRECEDES,
+  _NL_MONETARY_N_SEP_BY_SPACE,
+  _NL_MONETARY_P_SIGN_POSN,
+  _NL_MONETARY_N_SIGN_POSN,
+  _NL_MONETARY_INT_P_CS_PRECEDES,
+  _NL_MONETARY_INT_P_SEP_BY_SPACE,
+  _NL_MONETARY_INT_N_CS_PRECEDES,
+  _NL_MONETARY_INT_N_SEP_BY_SPACE,
+  _NL_MONETARY_INT_P_SIGN_POSN,
+  _NL_MONETARY_INT_N_SIGN_POSN,
+  _NL_MONETARY_CODESET,
+  _NL_MONETARY_WINT_CURR_SYMBOL,
+  _NL_MONETARY_WCURRENCY_SYMBOL,
+  _NL_MONETARY_WMON_DECIMAL_POINT,
+  _NL_MONETARY_WMON_THOUSANDS_SEP,
+  _NL_MONETARY_WPOSITIVE_SIGN,
+  _NL_MONETARY_WNEGATIVE_SIGN,
+
+  _NL_MESSAGES_WYESEXPR,
+  _NL_MESSAGES_WNOEXPR,
+  _NL_MESSAGES_WYESSTR,
+  _NL_MESSAGES_WNOSTR,
+
+  _NL_COLLATE_CODESET,
+
+  /* This MUST be the last entry since it's used to check for an array
+     index in nl_langinfo(). */
+  _NL_LOCALE_EXTENDED_LAST_ENTRY
+};
+
+#endif /* __HAVE_LOCALE_INFO_EXTENDED__ */
+#endif /* __HAVE_LOCALE_INFO__ */
+
 __BEGIN_DECLS
 char	*nl_langinfo(nl_item);
 __END_DECLS
Index: libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.38
diff -u -p -r1.38 stdlib.h
--- libc/include/stdlib.h	22 Dec 2009 13:07:24 -0000	1.38
+++ libc/include/stdlib.h	2 Mar 2010 20:33:47 -0000
@@ -55,9 +55,9 @@ typedef struct
 
 #define RAND_MAX __RAND_MAX
 
-extern __IMPORT int __mb_cur_max;
+int	_EXFUN(__locale_mb_cur_max,(_VOID));
 
-#define MB_CUR_MAX __mb_cur_max
+#define MB_CUR_MAX __locale_mb_cur_max()
 
 _VOID	_EXFUN(abort,(_VOID) _ATTRIBUTE ((noreturn)));
 int	_EXFUN(abs,(int));
Index: libc/locale/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/Makefile.am,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile.am
--- libc/locale/Makefile.am	1 May 2006 22:01:01 -0000	1.7
+++ libc/locale/Makefile.am	2 Mar 2010 20:33:47 -0000
@@ -17,7 +17,8 @@ ELIX_SOURCES = \
 	lnumeric.c \
 	lmonetary.c \
 	nl_langinfo.c \
-	timelocal.c
+	timelocal.c \
+	lctype.c
 endif
 
 liblocale_la_LDFLAGS = -Xcompiler -nostdlib
Index: libc/locale/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/Makefile.in,v
retrieving revision 1.23
diff -u -p -r1.23 Makefile.in
--- libc/locale/Makefile.in	2 Mar 2010 12:05:14 -0000	1.23
+++ libc/locale/Makefile.in	2 Mar 2010 20:33:47 -0000
@@ -62,7 +62,8 @@ am__objects_1 = lib_a-locale.$(OBJEXT)
 @ELIX_LEVEL_1_FALSE@	lib_a-lnumeric.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@	lib_a-lmonetary.$(OBJEXT) \
 @ELIX_LEVEL_1_FALSE@	lib_a-nl_langinfo.$(OBJEXT) \
-@ELIX_LEVEL_1_FALSE@	lib_a-timelocal.$(OBJEXT)
+@ELIX_LEVEL_1_FALSE@	lib_a-timelocal.$(OBJEXT) \
+@ELIX_LEVEL_1_FALSE@	lib_a-lctype.$(OBJEXT)
 @USE_LIBTOOL_FALSE@am_lib_a_OBJECTS = $(am__objects_1) \
 @USE_LIBTOOL_FALSE@	$(am__objects_2)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
@@ -71,7 +72,7 @@ liblocale_la_LIBADD =
 am__objects_3 = locale.lo
 @ELIX_LEVEL_1_FALSE@am__objects_4 = fix_grouping.lo ldpart.lo \
 @ELIX_LEVEL_1_FALSE@	lmessages.lo lnumeric.lo lmonetary.lo \
-@ELIX_LEVEL_1_FALSE@	nl_langinfo.lo timelocal.lo
+@ELIX_LEVEL_1_FALSE@	nl_langinfo.lo timelocal.lo lctype.lo
 @USE_LIBTOOL_TRUE@am_liblocale_la_OBJECTS = $(am__objects_3) \
 @USE_LIBTOOL_TRUE@	$(am__objects_4)
 liblocale_la_OBJECTS = $(am_liblocale_la_OBJECTS)
@@ -167,6 +168,7 @@ PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
 PACKAGE_NAME = @PACKAGE_NAME@
 PACKAGE_STRING = @PACKAGE_STRING@
 PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
 PACKAGE_VERSION = @PACKAGE_VERSION@
 PATH_SEPARATOR = @PATH_SEPARATOR@
 RANLIB = @RANLIB@
@@ -246,7 +248,8 @@ GENERAL_SOURCES = timelocal.h ldpart.h l
 @ELIX_LEVEL_1_FALSE@	lnumeric.c \
 @ELIX_LEVEL_1_FALSE@	lmonetary.c \
 @ELIX_LEVEL_1_FALSE@	nl_langinfo.c \
-@ELIX_LEVEL_1_FALSE@	timelocal.c
+@ELIX_LEVEL_1_FALSE@	timelocal.c \
+@ELIX_LEVEL_1_FALSE@	lctype.c
 
 @ELIX_LEVEL_1_TRUE@ELIX_SOURCES = 
 liblocale_la_LDFLAGS = -Xcompiler -nostdlib
@@ -378,6 +381,12 @@ lib_a-timelocal.o: timelocal.c
 lib_a-timelocal.obj: timelocal.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-timelocal.obj `if test -f 'timelocal.c'; then $(CYGPATH_W) 'timelocal.c'; else $(CYGPATH_W) '$(srcdir)/timelocal.c'; fi`
 
+lib_a-lctype.o: lctype.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lctype.o `test -f 'lctype.c' || echo '$(srcdir)/'`lctype.c
+
+lib_a-lctype.obj: lctype.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lctype.obj `if test -f 'lctype.c'; then $(CYGPATH_W) 'lctype.c'; else $(CYGPATH_W) '$(srcdir)/lctype.c'; fi`
+
 mostlyclean-libtool:
 	-rm -f *.lo
 
Index: libc/locale/lctype.c
===================================================================
RCS file: libc/locale/lctype.c
diff -N libc/locale/lctype.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libc/locale/lctype.c	2 Mar 2010 20:33:47 -0000
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+
+#include <limits.h>
+#include "lctype.h"
+#include "ldpart.h"
+
+#define LCCTYPE_SIZE (sizeof(struct lc_ctype_T) / sizeof(char *))
+
+static char	numone[] = { '\1', '\0'};
+
+static const struct lc_ctype_T _C_ctype_locale = {
+	"ASCII",			/* codeset */
+	numone				/* mb_cur_max */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+	, "0", "1", "2", "3", "4",	/* outdigits */
+	"5", "6", "7", "8", "9",
+	L"0", L"1", L"2", L"3", L"4",	/* woutdigits */
+	L"5", L"6", L"7", L"8", L"9"
+#endif
+};
+
+static struct lc_ctype_T _ctype_locale;
+static int	_ctype_using_locale;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+static char	*_ctype_locale_buf;
+#else
+/* Max encoding_len + NUL byte + 1 byte mb_cur_max plus trailing NUL byte */
+#define _CTYPE_BUF_SIZE	34
+static char _ctype_locale_buf[_CTYPE_BUF_SIZE];
+#endif
+
+int
+__ctype_load_locale(const char *name , void *f_wctomb, const char *charset,
+		    int mb_cur_max)
+{
+	int ret;
+
+#ifdef __CYGWIN__
+	extern int __set_lc_ctype_from_win (const char *,
+					    const struct lc_ctype_T *,
+					    struct lc_ctype_T *, char **,
+					    void *, const char *, int);
+	int old_ctype_using_locale = _ctype_using_locale;
+	_ctype_using_locale = 0;
+	ret = __set_lc_ctype_from_win (name, &_C_ctype_locale, &_ctype_locale,
+				       &_ctype_locale_buf, f_wctomb, charset,
+				       mb_cur_max);
+	/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
+	if (ret < 0)
+	  _ctype_using_locale = old_ctype_using_locale;
+	else
+	  {
+	    _ctype_using_locale = ret;
+	    ret = 0;
+	  }
+#elif !defined (__HAVE_LOCALE_INFO_EXTENDED__)
+	if (!strcmp (name, "C"))
+	  _ctype_using_locale = 0;
+	else
+	  {
+	    _ctype_locale.codeset = _ctype_locale_buf;
+	    _ctype_locale.mb_cur_max = _ctype_locale_buf + _CTYPE_BUF_SIZE - 2;
+	    strcpy (_ctype_locale.codeset, charset);
+	    _ctype_locale.mb_cur_max[0] = mb_cur_max;
+	    _ctype_locale.mb_cur_max[1] = '\0';
+	    _ctype_using_locale = 1;
+	  }
+	ret = 0;
+#else
+	ret = __part_load_locale(name, &_ctype_using_locale,
+		_ctype_locale_buf, "LC_CTYPE",
+		LCCTYPE_SIZE, LCCTYPE_SIZE,
+		(const char **)&_ctype_locale);
+	if (ret == 0 && _ctype_using_locale)
+		_ctype_locale.grouping =
+			__fix_locale_grouping_str(_ctype_locale.grouping);
+#endif
+	return ret;
+}
+
+struct lc_ctype_T *
+__get_current_ctype_locale(void) {
+
+	return (_ctype_using_locale
+		? &_ctype_locale
+		: (struct lc_ctype_T *)&_C_ctype_locale);
+}
Index: libc/locale/lctype.h
===================================================================
RCS file: libc/locale/lctype.h
diff -N libc/locale/lctype.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libc/locale/lctype.h	2 Mar 2010 20:33:47 -0000
@@ -0,0 +1,50 @@
+/*-
+ * 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.
+ */
+
+#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(const char *, void *, const char *, int);
+
+__END_DECLS
+
+#endif /* !_LCTYPE_H_ */
Index: libc/locale/lmessages.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/lmessages.c,v
retrieving revision 1.2
diff -u -p -r1.2 lmessages.c
--- libc/locale/lmessages.c	9 Feb 2010 08:58:38 -0000	1.2
+++ libc/locale/lmessages.c	2 Mar 2010 20:33:47 -0000
@@ -42,6 +42,13 @@ static const struct lc_messages_T _C_mes
 	"^[nN]" ,	/* noexpr */
 	"yes" , 	/* yesstr */
 	"no"		/* nostr */
+	"ASCII"		/* codeset */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+	, L"^[yY]" ,	/* wyesexpr */
+	L"^[nN]" ,	/* wnoexpr */
+	L"yes" , 	/* wyesstr */
+	L"no"		/* wnostr */
+#endif
 };
 
 static struct lc_messages_T _messages_locale;
@@ -53,13 +60,15 @@ __messages_load_locale (const char *name
 {
 #ifdef __CYGWIN__
 	extern int __set_lc_messages_from_win (const char *,
+					       const struct lc_messages_T *,
 					       struct lc_messages_T *, char **,
 					       void *, const char *);
 	int ret;
 
 	int old_messages_using_locale = _messages_using_locale;
 	_messages_using_locale = 0;
-	ret = __set_lc_messages_from_win (name, &_messages_locale,
+	ret = __set_lc_messages_from_win (name, &_C_messages_locale,
+					  &_messages_locale,
 					  &_messages_locale_buf,
 					  f_wctomb, charset);
 	/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
Index: libc/locale/lmessages.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/lmessages.h,v
retrieving revision 1.2
diff -u -p -r1.2 lmessages.h
--- libc/locale/lmessages.h	9 Feb 2010 08:58:38 -0000	1.2
+++ libc/locale/lmessages.h	2 Mar 2010 20:33:47 -0000
@@ -29,7 +29,9 @@
 #ifndef _LMESSAGES_H_
 #define	_LMESSAGES_H_
 
+#include <_ansi.h>
 #include <sys/cdefs.h>
+#include <wchar.h>
 
 __BEGIN_DECLS
 
@@ -38,6 +40,13 @@ struct	lc_messages_T {
 	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);
Index: libc/locale/lmonetary.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/lmonetary.c,v
retrieving revision 1.3
diff -u -p -r1.3 lmonetary.c
--- libc/locale/lmonetary.c	9 Feb 2010 08:58:38 -0000	1.3
+++ libc/locale/lmonetary.c	2 Mar 2010 20:33:47 -0000
@@ -38,6 +38,9 @@ extern const char * __fix_locale_groupin
 
 static char	empty[] = "";
 static char	numempty[] = { CHAR_MAX, '\0'};
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+static wchar_t	wempty[] = L"";
+#endif
 
 static const struct lc_monetary_T _C_monetary_locale = {
 	empty,		/* int_curr_symbol */
@@ -55,6 +58,21 @@ static const struct lc_monetary_T _C_mon
 	numempty,	/* n_sep_by_space */
 	numempty,	/* p_sign_posn */
 	numempty	/* n_sign_posn */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+	, numempty,	/* int_p_cs_precedes */
+	numempty,	/* int_p_sep_by_space */
+	numempty,	/* int_n_cs_precedes */
+	numempty,	/* int_n_sep_by_space */
+	numempty,	/* int_p_sign_posn */
+	numempty,	/* int_n_sign_posn */
+	"ASCII",	/* codeset */
+	wempty,		/* wint_curr_symbol */
+	wempty,		/* wcurrency_symbol */
+	wempty,		/* wmon_decimal_point */
+	wempty,		/* wmon_thousands_sep */
+	wempty,		/* wpositive_sign */
+	wempty		/* wnegative_sign */
+#endif
 };
 
 static struct lc_monetary_T _monetary_locale;
@@ -76,11 +94,13 @@ __monetary_load_locale(const char *name 
 
 #ifdef __CYGWIN__
 	extern int __set_lc_monetary_from_win (const char *,
+					       const struct lc_monetary_T *,
 					       struct lc_monetary_T *, char **,
 					       void *, const char *);
 	int old_monetary_using_locale = _monetary_using_locale;
 	_monetary_using_locale = 0;
-	ret = __set_lc_monetary_from_win (name, &_monetary_locale,
+	ret = __set_lc_monetary_from_win (name, &_C_monetary_locale,
+					  &_monetary_locale,
 					  &_monetary_locale_buf,
 					  f_wctomb, charset);
 	/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
Index: libc/locale/lmonetary.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/lmonetary.h,v
retrieving revision 1.2
diff -u -p -r1.2 lmonetary.h
--- libc/locale/lmonetary.h	22 Jan 2010 13:03:42 -0000	1.2
+++ libc/locale/lmonetary.h	2 Mar 2010 20:33:47 -0000
@@ -29,7 +29,9 @@
 #ifndef _LMONETARY_H_
 #define	_LMONETARY_H_
 
+#include <_ansi.h>
 #include <sys/cdefs.h>
+#include <wchar.h>
 
 __BEGIN_DECLS
 
@@ -49,6 +51,21 @@ struct lc_monetary_T {
 	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);
Index: libc/locale/lnumeric.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/lnumeric.c,v
retrieving revision 1.3
diff -u -p -r1.3 lnumeric.c
--- libc/locale/lnumeric.c	9 Feb 2010 08:58:38 -0000	1.3
+++ libc/locale/lnumeric.c	2 Mar 2010 20:33:47 -0000
@@ -24,8 +24,6 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
-
 #include <limits.h>
 #include "lnumeric.h"
 #include "ldpart.h"
@@ -38,9 +36,14 @@ extern const char *__fix_locale_grouping
 static char	numempty[] = { CHAR_MAX, '\0' };
 
 static const struct lc_numeric_T _C_numeric_locale = {
-	".",     	/* decimal_point */
-	"",     	/* thousands_sep */
-	numempty	/* grouping */
+	".",     			/* decimal_point */
+	"",     			/* thousands_sep */
+	numempty			/* grouping */
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+	, "ASCII",			/* codeset */
+	L".",				/* wdecimal_point */
+	L"",				/* wthousands_sep */
+#endif
 };
 
 static struct lc_numeric_T _numeric_locale;
@@ -54,12 +57,13 @@ __numeric_load_locale(const char *name ,
 
 #ifdef __CYGWIN__
 	extern int __set_lc_numeric_from_win (const char *,
+					      const struct lc_numeric_T *,
 					      struct lc_numeric_T *, char **,
 					      void *, const char *);
 	int old_numeric_using_locale = _numeric_using_locale;
 	_numeric_using_locale = 0;
-	ret = __set_lc_numeric_from_win (name, &_numeric_locale,
-					 &_numeric_locale_buf,
+	ret = __set_lc_numeric_from_win (name, &_C_numeric_locale,
+					 &_numeric_locale, &_numeric_locale_buf,
 					 f_wctomb, charset);
 	/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
 	if (ret < 0)
Index: libc/locale/lnumeric.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/lnumeric.h,v
retrieving revision 1.2
diff -u -p -r1.2 lnumeric.h
--- libc/locale/lnumeric.h	22 Jan 2010 13:03:42 -0000	1.2
+++ libc/locale/lnumeric.h	2 Mar 2010 20:33:47 -0000
@@ -29,7 +29,9 @@
 #ifndef _LNUMERIC_H_
 #define	_LNUMERIC_H_
 
+#include <_ansi.h>
 #include <sys/cdefs.h>
+#include <wchar.h>
 
 __BEGIN_DECLS
 
@@ -37,6 +39,11 @@ 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);
Index: libc/locale/locale.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/locale.c,v
retrieving revision 1.42
diff -u -p -r1.42 locale.c
--- libc/locale/locale.c	25 Feb 2010 16:16:16 -0000	1.42
+++ libc/locale/locale.c	2 Mar 2010 20:33:47 -0000
@@ -178,8 +178,10 @@ No supporting OS subroutines are require
 #include <reent.h>
 #include <stdlib.h>
 #include <wchar.h>
+#include "lmessages.h"
 #include "lmonetary.h"
 #include "lnumeric.h"
+#include "lctype.h"
 #include "../stdlib/local.h"
 
 #define _LC_LAST      7
@@ -817,8 +819,9 @@ restart:
     default:
       FAIL;
     }
-  if (category == LC_CTYPE)
+  switch (category)
     {
+    case LC_CTYPE:
       strcpy (lc_ctype_charset, charset);
       __mb_cur_max = mbc_max;
       __wctomb = l_wctomb;
@@ -834,27 +837,36 @@ restart:
 			  && ((strncmp (locale, "ja", 2) == 0
 			      || strncmp (locale, "ko", 2) == 0
 			      || strncmp (locale, "zh", 2) == 0));
-    }
-  else if (category == LC_MESSAGES)
-    {
+#ifdef __HAVE_LOCALE_INFO__
+      ret = __ctype_load_locale (locale, (void *) l_wctomb, charset, mbc_max);
+#endif /* __HAVE_LOCALE_INFO__ */
+      break;
+    case LC_MESSAGES:
+      strcpy (lc_message_charset, charset);
 #ifdef __HAVE_LOCALE_INFO__
       ret = __messages_load_locale (locale, (void *) l_wctomb, charset);
       if (!ret)
 #endif /* __HAVE_LOCALE_INFO__ */
-      strcpy (lc_message_charset, charset);
-    }
+      break;
 #ifdef __HAVE_LOCALE_INFO__
 #ifdef __CYGWIN__
   /* Right now only Cygwin supports a __collate_load_locale function at all. */
-  else if (category == LC_COLLATE)
-    ret = __collate_load_locale (locale, (void *) l_mbtowc, charset);
+    case LC_COLLATE:
+      ret = __collate_load_locale (locale, (void *) l_mbtowc, charset);
+      break;
 #endif
-  else if (category == LC_MONETARY)
-    ret = __monetary_load_locale (locale, (void *) l_wctomb, charset);
-  else if (category == LC_NUMERIC)
-    ret = __numeric_load_locale (locale, (void *) l_wctomb, charset);
-  else if (category == LC_TIME)
-    ret = __time_load_locale (locale, (void *) l_wctomb, charset);
+    case LC_MONETARY:
+      ret = __monetary_load_locale (locale, (void *) l_wctomb, charset);
+      break;
+    case LC_NUMERIC:
+      ret = __numeric_load_locale (locale, (void *) l_wctomb, charset);
+      break;
+    case LC_TIME:
+      ret = __time_load_locale (locale, (void *) l_wctomb, charset);
+      break;
+    default:
+      break;
+    }
   if (ret)
     FAIL;
 #endif /* __HAVE_LOCALE_INFO__ */
@@ -888,13 +900,32 @@ __get_locale_env(struct _reent *p, int c
 char *
 _DEFUN_VOID(__locale_charset)
 {
+#ifdef __HAVE_LOCALE_INFO__
+  return __get_current_ctype_locale ()->codeset;
+#else
   return lc_ctype_charset;
+#endif
+}
+
+int
+_DEFUN_VOID(__locale_mb_cur_max)
+{
+#ifdef __HAVE_LOCALE_INFO__
+  return __get_current_ctype_locale ()->mb_cur_max;
+#else
+  return __mb_cur_max;
+#endif
 }
 
+
 char *
 _DEFUN_VOID(__locale_msgcharset)
 {
+#ifdef __HAVE_LOCALE_INFO__
+  return __get_current_messages_locale ()->codeset;
+#else
   return lc_message_charset;
+#endif
 }
 
 int
@@ -934,12 +965,21 @@ _DEFUN(_localeconv_r, (data), 
       lconv.n_sep_by_space = m->n_sep_by_space[0];
       lconv.p_sign_posn = m->p_sign_posn[0];
       lconv.n_sign_posn = m->n_sign_posn[0];
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+      lconv.int_p_cs_precedes = m->int_p_cs_precedes[0];
+      lconv.int_p_sep_by_space = m->int_p_sep_by_space[0];
+      lconv.int_n_cs_precedes = m->int_n_cs_precedes[0];
+      lconv.int_n_sep_by_space = m->int_n_sep_by_space[0];
+      lconv.int_n_sign_posn = m->int_n_sign_posn[0];
+      lconv.int_p_sign_posn = m->int_p_sign_posn[0];
+#else /* !__HAVE_LOCALE_INFO_EXTENDED__ */
+      lconv.int_p_cs_precedes = m->p_cs_precedes[0];
+      lconv.int_p_sep_by_space = m->p_sep_by_space[0];
       lconv.int_n_cs_precedes = m->n_cs_precedes[0];
       lconv.int_n_sep_by_space = m->n_sep_by_space[0];
       lconv.int_n_sign_posn = m->n_sign_posn[0];
-      lconv.int_p_cs_precedes = m->p_cs_precedes[0];
-      lconv.int_p_sep_by_space = m->p_sep_by_space[0];
       lconv.int_p_sign_posn = m->p_sign_posn[0];
+#endif /* !__HAVE_LOCALE_INFO_EXTENDED__ */
       __mlocale_changed = 0;
     }
 #endif /* __HAVE_LOCALE_INFO__ */
Index: libc/locale/nl_langinfo.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/nl_langinfo.c,v
retrieving revision 1.10
diff -u -p -r1.10 nl_langinfo.c
--- libc/locale/nl_langinfo.c	22 Feb 2010 10:53:04 -0000	1.10
+++ libc/locale/nl_langinfo.c	2 Mar 2010 20:33:47 -0000
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "lctype.h"
 #include "timelocal.h"
 #include "lnumeric.h"
 #include "lmonetary.h"
@@ -41,6 +42,138 @@
 #define TRANSITION_PERIOD_HACK
 #endif
 
+#undef offsetoff
+#define _O(TYPE, MEMBER)  __builtin_offsetof (TYPE, MEMBER)
+
+#define _NLITEM(cat,memb) { { cat:__get_current_##cat##_locale }, \
+			      _O (struct lc_##cat##_T, memb) }
+
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+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);
+    void *		   (*base)(void);
+  };
+  _off_t offset;
+} nl_ext[] =
+{
+  /* First element has an nl_item value of _NL_LOCALE_EXTENDED_FIRST_ENTRY */
+  _NLITEM (ctype, outdigits[0]),
+  _NLITEM (ctype, outdigits[1]),
+  _NLITEM (ctype, outdigits[2]),
+  _NLITEM (ctype, outdigits[3]),
+  _NLITEM (ctype, outdigits[4]),
+  _NLITEM (ctype, outdigits[5]),
+  _NLITEM (ctype, outdigits[6]),
+  _NLITEM (ctype, outdigits[7]),
+  _NLITEM (ctype, outdigits[8]),
+  _NLITEM (ctype, outdigits[9]),
+  _NLITEM (ctype, woutdigits[0]),
+  _NLITEM (ctype, woutdigits[1]),
+  _NLITEM (ctype, woutdigits[2]),
+  _NLITEM (ctype, woutdigits[3]),
+  _NLITEM (ctype, woutdigits[4]),
+  _NLITEM (ctype, woutdigits[5]),
+  _NLITEM (ctype, woutdigits[6]),
+  _NLITEM (ctype, woutdigits[7]),
+  _NLITEM (ctype, woutdigits[8]),
+  _NLITEM (ctype, woutdigits[9]),
+  _NLITEM (time, codeset),
+  _NLITEM (time, wmon[1]),
+  _NLITEM (time, wmon[2]),
+  _NLITEM (time, wmon[3]),
+  _NLITEM (time, wmon[4]),
+  _NLITEM (time, wmon[5]),
+  _NLITEM (time, wmon[6]),
+  _NLITEM (time, wmon[7]),
+  _NLITEM (time, wmon[8]),
+  _NLITEM (time, wmon[9]),
+  _NLITEM (time, wmon[10]),
+  _NLITEM (time, wmon[11]),
+  _NLITEM (time, wmon[12]),
+  _NLITEM (time, wmonth[1]),
+  _NLITEM (time, wmonth[2]),
+  _NLITEM (time, wmonth[3]),
+  _NLITEM (time, wmonth[4]),
+  _NLITEM (time, wmonth[5]),
+  _NLITEM (time, wmonth[6]),
+  _NLITEM (time, wmonth[7]),
+  _NLITEM (time, wmonth[8]),
+  _NLITEM (time, wmonth[9]),
+  _NLITEM (time, wmonth[10]),
+  _NLITEM (time, wmonth[11]),
+  _NLITEM (time, wmonth[12]),
+  _NLITEM (time, wwday[1]),
+  _NLITEM (time, wwday[2]),
+  _NLITEM (time, wwday[3]),
+  _NLITEM (time, wwday[4]),
+  _NLITEM (time, wwday[5]),
+  _NLITEM (time, wwday[6]),
+  _NLITEM (time, wwday[7]),
+  _NLITEM (time, wweekday[1]),
+  _NLITEM (time, wweekday[2]),
+  _NLITEM (time, wweekday[3]),
+  _NLITEM (time, wweekday[4]),
+  _NLITEM (time, wweekday[5]),
+  _NLITEM (time, wweekday[6]),
+  _NLITEM (time, wweekday[7]),
+  _NLITEM (time, wX_fmt),
+  _NLITEM (time, wx_fmt),
+  _NLITEM (time, wc_fmt),
+  _NLITEM (time, wam_pm[0]),
+  _NLITEM (time, wam_pm[1]),
+  _NLITEM (time, wdate_fmt),
+  _NLITEM (time, wampm_fmt),
+  _NLITEM (time, wera),
+  _NLITEM (time, wera_d_fmt),
+  _NLITEM (time, wera_d_t_fmt),
+  _NLITEM (time, wera_t_fmt),
+  _NLITEM (time, walt_digits),
+  _NLITEM (numeric, codeset),
+  _NLITEM (numeric, grouping),
+  _NLITEM (numeric, wdecimal_point),
+  _NLITEM (numeric, wthousands_sep),
+  _NLITEM (monetary, int_curr_symbol),
+  _NLITEM (monetary, currency_symbol),
+  _NLITEM (monetary, mon_decimal_point),
+  _NLITEM (monetary, mon_thousands_sep),
+  _NLITEM (monetary, mon_grouping),
+  _NLITEM (monetary, positive_sign),
+  _NLITEM (monetary, negative_sign),
+  _NLITEM (monetary, int_frac_digits),
+  _NLITEM (monetary, frac_digits),
+  _NLITEM (monetary, p_cs_precedes),
+  _NLITEM (monetary, p_sep_by_space),
+  _NLITEM (monetary, n_cs_precedes),
+  _NLITEM (monetary, n_sep_by_space),
+  _NLITEM (monetary, p_sign_posn),
+  _NLITEM (monetary, n_sign_posn),
+  _NLITEM (monetary, int_p_cs_precedes),
+  _NLITEM (monetary, int_p_sep_by_space),
+  _NLITEM (monetary, int_n_cs_precedes),
+  _NLITEM (monetary, int_n_sep_by_space),
+  _NLITEM (monetary, int_p_sign_posn),
+  _NLITEM (monetary, int_n_sign_posn),
+  _NLITEM (monetary, codeset),
+  _NLITEM (monetary, wint_curr_symbol),
+  _NLITEM (monetary, wcurrency_symbol),
+  _NLITEM (monetary, wmon_decimal_point),
+  _NLITEM (monetary, wmon_thousands_sep),
+  _NLITEM (monetary, wpositive_sign),
+  _NLITEM (monetary, wnegative_sign),
+  _NLITEM (messages, codeset),
+  _NLITEM (messages, wyesexpr),
+  _NLITEM (messages, wnoexpr),
+  _NLITEM (messages, wyesstr),
+  _NLITEM (messages, wnostr),
+};
+#endif /* __HAVE_LOCALE_INFO_EXTENDED__ */
+
 #define _REL(BASE) ((int)item-BASE)
 
 extern char *__locale_charset ();
@@ -57,9 +190,36 @@ _DEFUN(nl_langinfo, (item), 
    char *nptr;
 
    switch (item) {
+#ifdef __HAVE_LOCALE_INFO__
+	case _NL_MESSAGES_CODESET:
+	      	ret = (char *) __get_current_messages_locale ()->codeset;
+		goto do_codeset;
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+	case _NL_TIME_CODESET:
+	      	ret = (char *) __get_current_time_locale ()->codeset;
+		goto do_codeset;
+	case _NL_NUMERIC_CODESET:
+	      	ret = (char *) __get_current_numeric_locale ()->codeset;
+		goto do_codeset;
+	case _NL_MONETARY_CODESET:
+	      	ret = (char *) __get_current_monetary_locale ()->codeset;
+		goto do_codeset;
+#ifdef __CYGWIN__
+	case _NL_COLLATE_CODESET:
+		{
+		  extern const char *__get_current_collate_codeset (void);
+		  ret = (char *) __get_current_collate_codeset ();
+		  goto do_codeset;
+		}
+#endif /* __CYGWIN__ */
+#endif /* __HAVE_LOCALE_INFO_EXTENDED__ */
+#endif /* __HAVE_LOCALE_INFO__ */
 	case CODESET:
 #ifdef __CYGWIN__
 		ret = __locale_charset ();
+#endif
+do_codeset:
+#ifdef __CYGWIN__
 		/* Convert charset to Linux compatible codeset string. */
 		if (ret[0] == 'A'/*SCII*/)
 		  ret = "ANSI_X3.4-1968";
@@ -250,7 +410,18 @@ _DEFUN(nl_langinfo, (item), 
 	case D_MD_ORDER:        /* local extension */
 		ret = (char *) __get_current_time_locale()->md_order;
 		break;
+	case _NL_CTYPE_MB_CUR_MAX:
+		ret = (char *) __get_current_ctype_locale()->mb_cur_max;
+		break;
 	default:
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+		if (item > _NL_LOCALE_EXTENDED_FIRST_ENTRY
+		    && item < _NL_LOCALE_EXTENDED_LAST_ENTRY) {
+			int idx = item - _NL_LOCALE_EXTENDED_FIRST_ENTRY - 1;
+			return *(char **) ((char *) (*nl_ext[idx].base)()
+					   + nl_ext[idx].offset);
+		}
+#endif
 		ret = "";
    }
    return (ret);
Index: libc/locale/timelocal.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/timelocal.c,v
retrieving revision 1.4
diff -u -p -r1.4 timelocal.c
--- libc/locale/timelocal.c	18 Feb 2010 17:35:15 -0000	1.4
+++ libc/locale/timelocal.c	2 Mar 2010 20:33:47 -0000
@@ -119,6 +119,34 @@ static const struct lc_time_T	_C_time_lo
 	 * Alternate digits used if %O format prefix is specified
 	 */
 	""
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+	, "ASCII",	/* codeset */
+	{
+		L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun",
+		L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec"
+	}, {
+		L"January", L"February", L"March", L"April", L"May", L"June",
+		L"July", L"August", L"September", L"October", L"November",
+		L"December"
+	}, {
+		L"Sun", L"Mon", L"Tue", L"Wed",
+		L"Thu", L"Fri", L"Sat"
+	}, {
+		L"Sunday", L"Monday", L"Tuesday", L"Wednesday",
+		L"Thursday", L"Friday", L"Saturday"
+	},
+	L"%H:%M:%S",
+	L"%m/%d/%y",
+	L"%a %b %e %H:%M:%S %Y",
+	{ L"AM", L"PM" },
+	L"%a %b %e %H:%M:%S %Z %Y",
+	L"%I:%M:%S %p",
+	L"",
+	L"",
+	L"",
+	L"",
+	L""
+#endif
 };
 
 struct lc_time_T *
@@ -134,12 +162,14 @@ __time_load_locale(const char *name, voi
 	int	ret;
 
 #ifdef __CYGWIN__
-	extern int __set_lc_time_from_win (const char *, struct lc_time_T *,
+	extern int __set_lc_time_from_win (const char *,
+					   const struct lc_time_T *,
+					   struct lc_time_T *,
 					   char **, void *, const char *);
 	int old_time_using_locale = _time_using_locale;
 	_time_using_locale = 0;
-	ret = __set_lc_time_from_win (name, &_time_locale, &time_locale_buf,
-				      f_wctomb, charset);
+	ret = __set_lc_time_from_win (name, &_C_time_locale, &_time_locale,
+				      &time_locale_buf, f_wctomb, charset);
 	/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
 	if (ret < 0)
 	  _time_using_locale = old_time_using_locale;
Index: libc/locale/timelocal.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/locale/timelocal.h,v
retrieving revision 1.3
diff -u -p -r1.3 timelocal.h
--- libc/locale/timelocal.h	18 Feb 2010 17:35:15 -0000	1.3
+++ libc/locale/timelocal.h	2 Mar 2010 20:33:47 -0000
@@ -29,7 +29,9 @@
 #ifndef _TIMELOCAL_H_
 #define	_TIMELOCAL_H_
 
+#include <_ansi.h>
 #include <sys/cdefs.h>
+#include <wchar.h>
 
 __BEGIN_DECLS
 
@@ -47,7 +49,7 @@ struct lc_time_T {
 	const char	*c_fmt;
 	const char	*am_pm[2];
 	const char	*date_fmt;
-	const char	*alt_month[12];
+	const char	*alt_month[12];	/* unused */
 	const char	*md_order;
 	const char	*ampm_fmt;
 	const char	*era;
@@ -55,6 +57,24 @@ struct lc_time_T {
 	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);
Index: libc/stdio/vfwprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfwprintf.c,v
retrieving revision 1.4
diff -u -p -r1.4 vfwprintf.c
--- libc/stdio/vfwprintf.c	15 Feb 2010 16:29:15 -0000	1.4
+++ libc/stdio/vfwprintf.c	2 Mar 2010 20:33:48 -0000
@@ -130,6 +130,9 @@ SEEALSO
 #include "local.h"
 #include "fvwrite.h"
 #include "vfieeefp.h"
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+#include "../locale/lnumeric.h"
+#endif
 
 /* Currently a test is made to see if long double processing is warranted.
    This could be changed in the future should the _ldtoa_r code be
@@ -444,6 +447,9 @@ _DEFUN(_VFWPRINTF_R, (data, fp, fmt0, ap
 
 #ifdef FLOATING_POINT
 #ifdef _MB_CAPABLE
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+	decimal_point = *__get_current_numeric_locale ()->wdecimal_point;
+#else
 	{
 	  size_t nconv;
 
@@ -454,6 +460,7 @@ _DEFUN(_VFWPRINTF_R, (data, fp, fmt0, ap
 	  if (nconv == (size_t) -1 || nconv == (size_t) -2)
 	    decimal_point = L'.';
 	}
+#endif
 #else
 	decimal_point = (wchar_t) *_localeconv_r (data)->decimal_point;
 #endif
@@ -626,6 +633,9 @@ reswitch:	switch (ch) {
 #ifdef _WANT_IO_C99_FORMATS
 		case L'\'':
 #ifdef _MB_CAPABLE
+#ifdef __HAVE_LOCALE_INFO_EXTENDED__
+		  thousands_sep = *__get_current_numeric_locale ()->wthousands_sep;
+#else
 		  {
 		    size_t nconv;
 
@@ -636,6 +646,7 @@ reswitch:	switch (ch) {
 		    if (nconv == (size_t) -1 || nconv == (size_t) -2)
 		      thousands_sep = L'\0';
 		  }
+#endif
 #else
 		  thousands_sep = (wchar_t) *_localeconv_r(data)->thousands_sep;
 #endif
Index: libc/time/strftime.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/time/strftime.c,v
retrieving revision 1.14
diff -u -p -r1.14 strftime.c
--- libc/time/strftime.c	26 Feb 2010 09:41:44 -0000	1.14
+++ libc/time/strftime.c	2 Mar 2010 20:33:48 -0000
@@ -260,6 +260,8 @@ BUGS
 the "C" locale settings.
 */
 
+#include <newlib.h>
+#include <sys/config.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <time.h>
@@ -300,18 +302,23 @@ the "C" locale settings.
 #  define STRCHR(a,b)	wcschr((a),(b))
 #  define STRLEN(a)	wcslen(a)
 #  define SFLG		"l"		/* %s flag (l for wide char) */
-#  define CTLOCBUFLEN   256		/* Arbitrary big buffer size */
-   const wchar_t *
-   __ctloc (wchar_t *buf, const char *elem, size_t *len_ret)
-   {
-     buf[CTLOCBUFLEN - 1] = L'\0';
-     *len_ret = mbstowcs (buf, elem, CTLOCBUFLEN - 1);
-     if (*len_ret == (size_t) -1 )
-       *len_ret = 0;
-     return buf;
-   }
-#  define _ctloc(x) (ctloc = __ctloc (ctlocbuf, _CurrentTimeLocale->x, \
-		     &ctloclen))
+#  ifdef __HAVE_LOCALE_INFO_EXTENDED__
+#   define _ctloc(x) (ctloclen = wcslen (ctloc = _CurrentTimeLocale->w##x), \
+		      ctloc)
+#  else
+#   define CTLOCBUFLEN   256		/* Arbitrary big buffer size */
+    const wchar_t *
+    __ctloc (wchar_t *buf, const char *elem, size_t *len_ret)
+    {
+      buf[CTLOCBUFLEN - 1] = L'\0';
+      *len_ret = mbstowcs (buf, elem, CTLOCBUFLEN - 1);
+      if (*len_ret == (size_t) -1 )
+	*len_ret = 0;
+      return buf;
+    }
+#   define _ctloc(x) (ctloc = __ctloc (ctlocbuf, _CurrentTimeLocale->x, \
+		      &ctloclen))
+#  endif
 #endif  /* MAKE_WCSFTIME */
 
 #define CHECK_LENGTH()	if (len < 0 || (count += len) >= maxsize) \
@@ -380,10 +387,25 @@ typedef struct {
 } era_info_t;
 
 static era_info_t *
+#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__)
+get_era_info (const struct tm *tim_p, const wchar_t *era)
+#else
 get_era_info (const struct tm *tim_p, const char *era)
+#endif
 {
+#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__)
+  wchar_t *c;
+  const wchar_t *dir;
+# define ERA_STRCHR(a,b)	wcschr((a),(b))
+# define ERA_STRNCPY(a,b,c)	wcsncpy((a),(b),(c))
+# define ERA_STRTOL(a,b,c)	wcstol((a),(b),(c))
+#else
   char *c;
   const char *dir;
+# define ERA_STRCHR(a,b)	strchr((a),(b))
+# define ERA_STRNCPY(a,b,c)	strncpy((a),(b),(c))
+# define ERA_STRTOL(a,b,c)	strtol((a),(b),(c))
+#endif
   long offset;
   struct tm stm, etm;
   era_info_t *ei;
@@ -397,14 +419,14 @@ get_era_info (const struct tm *tim_p, co
     {
       dir = era;
       era += 2;
-      offset = strtol (era, &c, 10);
+      offset = ERA_STRTOL (era, &c, 10);
       era = c + 1;
-      stm.tm_year = strtol (era, &c, 10) - YEAR_BASE;
+      stm.tm_year = ERA_STRTOL (era, &c, 10) - YEAR_BASE;
       /* Adjust offset for negative gregorian dates. */
       if (stm.tm_year <= -YEAR_BASE)
       	++stm.tm_year;
-      stm.tm_mon = strtol (c + 1, &c, 10);
-      stm.tm_mday = strtol (c + 1, &c, 10);
+      stm.tm_mon = ERA_STRTOL (c + 1, &c, 10);
+      stm.tm_mday = ERA_STRTOL (c + 1, &c, 10);
       stm.tm_hour = stm.tm_min = stm.tm_sec = 0;
       era = c + 1;
       if (era[0] == '-' && era[1] == '*')
@@ -425,12 +447,12 @@ get_era_info (const struct tm *tim_p, co
 	}
       else
       	{
-	  etm.tm_year = strtol (era, &c, 10) - YEAR_BASE;
+	  etm.tm_year = ERA_STRTOL (era, &c, 10) - YEAR_BASE;
 	  /* Adjust offset for negative gregorian dates. */
 	  if (etm.tm_year <= -YEAR_BASE)
 	    ++etm.tm_year;
-	  etm.tm_mon = strtol (c + 1, &c, 10);
-	  etm.tm_mday = strtol (c + 1, &c, 10);
+	  etm.tm_mon = ERA_STRTOL (c + 1, &c, 10);
+	  etm.tm_mday = ERA_STRTOL (c + 1, &c, 10);
 	  etm.tm_mday = 31;
 	  etm.tm_hour = 23;
 	  etm.tm_min = etm.tm_sec = 59;
@@ -456,8 +478,8 @@ get_era_info (const struct tm *tim_p, co
 	  else
 	    ei->year = etm.tm_year - tim_p->tm_year + offset;
 	  /* era_C */
-	  c = strchr (era, ':');
-#ifdef MAKE_WCSFTIME
+	  c = ERA_STRCHR (era, ':');
+#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
 	  len = mbsnrtowcs (NULL, &era, c - era, 0, NULL);
 	  if (len == (size_t) -1)
 	    {
@@ -473,19 +495,19 @@ get_era_info (const struct tm *tim_p, co
 	      free (ei);
 	      return NULL;
 	    }
-#ifdef MAKE_WCSFTIME
+#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
 	  len = mbsnrtowcs (ei->era_C, &era, c - era, len + 1, NULL);
 #else
-	  strncpy (ei->era_C, era, len);
+	  ERA_STRNCPY (ei->era_C, era, len);
 	  era += len;
 #endif
 	  ei->era_C[len] = CQ('\0');
 	  /* era_Y */
 	  ++era;
-	  c = strchr (era, ';');
+	  c = ERA_STRCHR (era, ';');
 	  if (!c)
-	    c = strchr (era, '\0');
-#ifdef MAKE_WCSFTIME
+	    c = ERA_STRCHR (era, '\0');
+#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
 	  len = mbsnrtowcs (NULL, &era, c - era, 0, NULL);
 	  if (len == (size_t) -1)
 	    {
@@ -503,17 +525,17 @@ get_era_info (const struct tm *tim_p, co
 	      free (ei);
 	      return NULL;
 	    }
-#ifdef MAKE_WCSFTIME
+#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
 	  len = mbsnrtowcs (ei->era_Y, &era, c - era, len + 1, NULL);
 #else
-	  strncpy (ei->era_Y, era, len);
+	  ERA_STRNCPY (ei->era_Y, era, len);
 	  era += len;
 #endif
 	  ei->era_Y[len] = CQ('\0');
 	  return ei;
 	}
       else
-	era = strchr (era, ';');
+	era = ERA_STRCHR (era, ';');
       if (era)
 	++era;
     }
@@ -535,10 +557,24 @@ typedef struct {
 } alt_digits_t;
 
 static alt_digits_t *
+#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__)
+get_alt_digits (const wchar_t *alt_digits)
+#else
 get_alt_digits (const char *alt_digits)
+#endif
 {
   alt_digits_t *adi;
+#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__)
+  const wchar_t *a, *e;
+# define ALT_STRCHR(a,b)	wcschr((a),(b))
+# define ALT_STRCPY(a,b)	wcscpy((a),(b))
+# define ALT_STRLEN(a)		wcslen(a)
+#else
   const char *a, *e;
+# define ALT_STRCHR(a,b)	strchr((a),(b))
+# define ALT_STRCPY(a,b)	strcpy((a),(b))
+# define ALT_STRLEN(a)		strlen(a)
+#endif
   CHAR *aa, *ae;
   size_t len;
 
@@ -548,7 +584,7 @@ get_alt_digits (const char *alt_digits)
 
   /* Compute number of alt_digits. */
   adi->num = 1;
-  for (a = alt_digits; (e = strchr (a, ';')) != NULL; a = e + 1)
+  for (a = alt_digits; (e = ALT_STRCHR (a, ';')) != NULL; a = e + 1)
       ++adi->num;
   /* Allocate the `digit' array, which is an array of `num' pointers into
      `buffer'. */
@@ -559,7 +595,7 @@ get_alt_digits (const char *alt_digits)
       return NULL;
     }
   /* Compute memory required for `buffer'. */
-#ifdef MAKE_WCSFTIME
+#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
   len = mbstowcs (NULL, alt_digits, 0);
   if (len == (size_t) -1)
     {
@@ -568,7 +604,7 @@ get_alt_digits (const char *alt_digits)
       return NULL;
     }
 #else
-  len = strlen (alt_digits);
+  len = ALT_STRLEN (alt_digits);
 #endif
   /* Allocate it. */
   adi->buffer = (CHAR *) malloc ((len + 1) * sizeof (CHAR));
@@ -579,10 +615,10 @@ get_alt_digits (const char *alt_digits)
       return NULL;
     }
   /* Store digits in it. */
-#ifdef MAKE_WCSFTIME
+#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
   mbstowcs (adi->buffer, alt_digits, len + 1);
 #else
-  strcpy (adi->buffer, alt_digits);
+  ALT_STRCPY (adi->buffer, alt_digits);
 #endif
   /* Store the pointers into `buffer' into the appropriate `digit' slot. */
   for (len = 0, aa = adi->buffer; (ae = STRCHR (aa, CQ(';'))) != NULL;
@@ -658,7 +694,7 @@ _DEFUN (strftime, (s, maxsize, format, t
   size_t count = 0;
   int i, len;
   const CHAR *ctloc;
-#ifdef MAKE_WCSFTIME
+#if defined (MAKE_WCSFTIME) && !defined (__HAVE_LOCALE_INFO_EXTENDED__)
   CHAR ctlocbuf[CTLOCBUFLEN];
 #endif
   size_t ctloclen;
@@ -700,16 +736,26 @@ _DEFUN (strftime, (s, maxsize, format, t
 	{
 	  alt = *format++;
 #ifdef _WANT_C99_TIME_FORMATS      
+#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__)
+	  if (!*era_info && *_CurrentTimeLocale->wera)
+	    *era_info = get_era_info (tim_p, _CurrentTimeLocale->wera);
+#else
 	  if (!*era_info && *_CurrentTimeLocale->era)
 	    *era_info = get_era_info (tim_p, _CurrentTimeLocale->era);
+#endif
 #endif /* _WANT_C99_TIME_FORMATS */
 	}
       else if (*format == CQ('O'))
 	{
 	  alt = *format++;
 #ifdef _WANT_C99_TIME_FORMATS      
+#if defined (MAKE_WCSFTIME) && defined (__HAVE_LOCALE_INFO_EXTENDED__)
+	  if (!*alt_digits && *_CurrentTimeLocale->walt_digits)
+	    *alt_digits = get_alt_digits (_CurrentTimeLocale->walt_digits);
+#else
 	  if (!*alt_digits && *_CurrentTimeLocale->alt_digits)
 	    *alt_digits = get_alt_digits (_CurrentTimeLocale->alt_digits);
+#endif
 #endif /* _WANT_C99_TIME_FORMATS */
 	}
 


-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]