[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patches] OPTION_EGLIBC_LOCALE_CODE option group



I've committed the following, which implements the
OPTION_EGLIBC_LOCALE_CODE option group, containing locale-specific
code.

Here's the documentation for OPTION_EGLIBC_LOCALE_CODE:

config OPTION_EGLIBC_LOCALE_CODE
   bool "Locale functions"
   help
       This option group includes locale support functions, programs,
       and libraries.  With OPTION_EGLIBC_LOCALE_FUNCTIONS disabled,
       EGLIBC supports only the 'C' locale (also known as 'POSIX'),
       and ignores the settings of the 'LANG' and 'LC_*' environment
       variables.

       With OPTION_EGLIBC_LOCALE_CODE disabled, the following
       functions are omitted from libc:

         duplocale   localeconv  nl_langinfo    rpmatch  strfmon_l
         freelocale  newlocale   nl_langinfo_l  strfmon  uselocale

       Furthermore, only the LC_CTYPE and LC_TIME categories of the
       standard "C" locale are available.

ChangeLog.eglibc:
2007-05-26  Jim Blandy  <jimb@xxxxxxxxxxxxxxxx>

	Add the OPTION_EGLIBC_LOCALE_CODE option group.

	* option-groups.def (OPTION_EGLIBC_LOCALE_CODE): New entry.
	* option-groups.defaults (OPTION_EGLIBC_LOCALE_CODE): Initialize.
	* Makerules (test-srcs): Add in value of test-srcs-y.
	(static-only-routines): Add in value of static-only-routines-y.
	* stdlib/Makefile: Include ../option-groups.mak.
	(routines): Move rpmatch, strfmon, and strfmon_l into the group.
	(tests): Move tst-strtod3 into the group.
	* wcsmbs/Makefile: Include ../option-groups.mak.
	(tests): Move tst-btowc, tst-mbrtowc, tst-mbrtowc2, and
	tst-wcrtomb into the option group.
	(CFLAGS-wcsmbsload.c): Define OPTION_EGLIBC_LOCALE_CODE as
	appropriate.
	* wcsmbs/wcsmbsload.c (__wcsmbs_load_conv): If the group is not
	enabled, simply abort.
	* time/Makefile: Include ../option-groups.mak.
	(aux): Move alt_digit, era, and lc-time-cleanup into the group.
	(tests): Move tst-strptime into the group.
	(CFLAGS-strftime_l.c, CFLAGS-strptime_l.c): Define
	OPTION_EGLIBC_LOCALE_CODE as appropriate.
	* time/strftime_l.c, time/strptime_l.c: Support eras and custom
	digits only when the group is enabled.
	* libio/Makefile (tests): Move tst-swscanf into the group.
	* intl/Makefile (CFLAGS-dcigettext.c): Define
	OPTION_EGLIBC_LOCALE_CODE as appropriate.
	* intl/dcigettext.c (DCIGETTEXT): If the group is not enabled,
	assume the "C" locale.
	* string/Makefile: Include ../option-groups.mak.
	(tests): Move tst-strxfrm and bug-strcoll1 into the option group.
	(CFLAGS-strerror_l.c): Define OPTION_EGLIBC_LOCALE_CODE as
	appropriate.
	* string/strerror_l.c (translate): Don't translate unless the
	group is enabled.
	* iconv/Makefile: Include ../option-groups.mak.
	(CFLAGS-gconv_db.c, CFLAGS-iconv_prog.c): Define
	OPTION_EGLIBC_LOCALE_CODE as appropriate.
	* iconv/gconv_db.c (libc_freeres_fn): If group is disabled, no
	need to free locale memory first.
	* iconv/iconv_prog.c (main): If the group is disabled, the default
	codeset is always ASCII.
	* locale/Makefile: Include ../option-groups.mak.
	(distribute): Mention new dummy-setlocale.c.
	(routines): Include mb_cur_max and the new catnames unconditionally;
	put setlocale, findlocale, loadlocale, loadarchive, localeconv,
	nl_langinfo, nl_langinfo_l, newlocale, duplocale, freelocale, and
	uselocale in the group.  If the group is disabled, use
	dummy-setlocale.
	(tests): Put tst-C-locale in the group.
	(aux): Move all C categories other than C-ctype and C-time into
	the group, along with all the load-locale routines, and
	localename.
	(others, install-bin, extra-objs): Put localedef and locale in the
	group.
	(extra-libs, extra-libs-other): Put libBrokenLocale in the group.
	(CFLAGS-xlocale.c): Define OPTION_EGLIBC_LOCALE_CODE as appropriate.
	* locale/xlocale.c: If the group is disabled, make the references
	here to the omitted category data weak.  Furthermore, in the
	NL_CURRENT_INDIRECT case, define the _nl_current_##CATEGORY
	variables here.
	* locale/setlocale.c (_nl_category_names, _nl_category_name_idxs)
	(_nl_category_name_sizes): Move these from here...
	* locale/catnames.c: ... to here.  New file.
	* locale/dummy-setlocale.c: New file.
	* intl/Makefile: Include ../option-groups.mak.
	(tests): Move tst-translit, tst-gettext2, tst-codeset,
	tst-gettext3, tst-gettext4, tst-gettext5, and mtrace-tst-gettext
	into the OPTION_EGLIBC_LOCALES option group.
	* localedata/Makefile (tests): Move all tests into the
	OPTION_EGLIBC_LOCALES group.
	* posix/Makefile (tests): Move tst-fnmatch, tst-regex,
	tst-regexloc, bug-regex1, bug-regex5, bug-regex19, bug-regex22,
	and bug-regex25 into the group.
	* stdio-common/Makefile: Include ../option-groups.mak.
	(tests): Move tst-sscanf, tst-swprintf, bug15, and test-vfprintf
	into the option group.
	(CFLAGS-printf_fp.c, CFLAGS-printf_fphex.c): Define
	OPTION_EGLIBC_LOCALE_CODE as appropriate.
	* stdio-common/printf_fp.c (__printf_fp): Hard-code values from
	the 'C' locale.
	* stdio-common/printf_fphex.c (__printf_fphex): Same.
	* libidn/Makefile: Include ../option-groups.mak.
	(CFLAGS-toutf8.c): Define OPTION_EGLIBC_LOCALE_CODE as appropriate.
	* libidn/toutf8.c (stringprep_locale_charset): If the group is
	disabled, assume ASCII.

Index: stdlib/Makefile
===================================================================
--- stdlib/Makefile	(revision 2332)
+++ stdlib/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Makefile for stdlib routines
 #
+include ../option-groups.mak
+
 subdir	:= stdlib
 
 headers	:= stdlib.h bits/stdlib.h bits/stdlib-ldbl.h			      \
@@ -28,7 +30,7 @@
 	   ucontext.h sys/ucontext.h					      \
 	   alloca.h fmtmsg.h
 
-routines	:=							      \
+routines-y	:=							      \
 	atof atoi atol atoll						      \
 	abort								      \
 	bsearch qsort msort						      \
@@ -49,9 +51,11 @@
 	strtof_l strtod_l strtold_l					      \
 	system canonicalize						      \
 	a64l l64a							      \
-	rpmatch strfmon strfmon_l getsubopt xpg_basename fmtmsg		      \
+	getsubopt xpg_basename fmtmsg					      \
 	strtoimax strtoumax wcstoimax wcstoumax				      \
 	getcontext setcontext makecontext swapcontext
+routines-$(OPTION_EGLIBC_LOCALE_CODE) +=				      \
+	rpmatch strfmon strfmon_l
 aux =	grouping groupingwc
 
 # These routines will be omitted from the libc shared object.
@@ -67,9 +71,10 @@
 		   tst-xpg-basename tst-random tst-random2 tst-bsearch	    \
 		   tst-limits tst-rand48 bug-strtod tst-setcontext	    \
 		   test-a64l tst-qsort tst-system testmb2 bug-strtod2	    \
-		   tst-atof1 tst-atof2 tst-strtod2 tst-strtod3 tst-rand48-2 \
+		   tst-atof1 tst-atof2 tst-strtod2 tst-rand48-2             \
 		   tst-makecontext tst-strtod4
-
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+		+= tst-strtod3
 include ../Makeconfig
 
 ifeq ($(build-shared),yes)
Index: wcsmbs/Makefile
===================================================================
--- wcsmbs/Makefile	(revision 2332)
+++ wcsmbs/Makefile	(working copy)
@@ -20,6 +20,8 @@
 #
 #	Sub-makefile for wcsmbs portion of the library.
 #
+include ../option-groups.mak
+
 subdir	:= wcsmbs
 
 headers	:= wchar.h bits/wchar.h bits/wchar2.h bits/wchar-ldbl.h
@@ -40,8 +42,10 @@
 	    wcscasecmp wcsncase wcscasecmp_l wcsncase_l \
 	    wcsmbsload mbsrtowcs_l
 
-tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \
-	 tst-wcrtomb tst-wcpncpy tst-mbsrtowcs tst-wchar-h tst-mbrtowc2
+tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen \
+	 tst-wcpncpy tst-mbsrtowcs tst-wchar-h
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+      += tst-btowc tst-mbrtowc tst-mbrtowc2 tst-wcrtomb
 
 include ../Rules
 
@@ -65,6 +69,10 @@
 CFLAGS-wcstof_l.c = $(strtox-CFLAGS)
 CFLAGS-tst-wchar-h.c = -D_FORTIFY_SOURCE=2
 
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+CFLAGS-wcsmbsload.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+
 # We need to find the default version of strtold_l in stdlib.
 CPPFLAGS-wcstold_l.c = -I../stdlib
 
Index: wcsmbs/wcsmbsload.c
===================================================================
--- wcsmbs/wcsmbsload.c	(revision 2332)
+++ wcsmbs/wcsmbsload.c	(working copy)
@@ -144,6 +144,7 @@
   })
 
 
+#ifdef OPTION_EGLIBC_LOCALE_CODE
 /* Some of the functions here must not be used while setlocale is called.  */
 __libc_lock_define (extern, __libc_setlocale_lock attribute_hidden)
 
@@ -213,6 +214,17 @@
 
   __libc_lock_unlock (__libc_setlocale_lock);
 }
+#else
+void
+internal_function
+__wcsmbs_load_conv (struct locale_data *new_category)
+{
+  /* When OPTION_EGLIBC_LOCALE_CODE is disabled, we should never reach
+     this point: there is no way to change locales, so every locale
+     passed to get_gconv_fcts should be _nl_C_LC_CTYPE.  */
+  abort ();
+}
+#endif
 
 
 /* Clone the current conversion function set.  */
Index: time/Makefile
===================================================================
--- time/Makefile	(revision 2332)
+++ time/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Makefile for time routines
 #
+include ../option-groups.mak
+
 subdir	:= time
 
 headers	:= time.h sys/time.h sys/timeb.h bits/time.h
@@ -30,13 +32,15 @@
 	    stime dysize timegm ftime			 \
 	    getdate strptime strptime_l			 \
 	    strftime wcsftime strftime_l wcsftime_l
-aux :=	    era alt_digit lc-time-cleanup
+aux-$(OPTION_EGLIBC_LOCALE_CODE) += alt_digit era lc-time-cleanup
 distribute := datemsk
 
-tests	:= test_time clocktest tst-posixtz tst-strptime tst_wcsftime \
+tests	:= test_time clocktest tst-posixtz tst_wcsftime \
 	   tst-getdate tst-mktime tst-mktime2 tst-ftime_l tst-strftime \
 	   tst-mktime3 tst-strptime2 bug-asctime bug-asctime_r bug-mktime1 \
 	   tst-strptime3
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+	+= tst-strptime
 
 include ../Rules
 
@@ -48,6 +52,12 @@
 CFLAGS-tzset.c = $(tz-cflags)
 CFLAGS-getdate.c = -fexceptions
 
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+
+CFLAGS-strftime_l.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+CFLAGS-strptime_l.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+
 # Don't warn about Y2k problem in strftime format string.
 CFLAGS-test_time.c = -Wno-format
 
Index: time/strftime_l.c
===================================================================
--- time/strftime_l.c	(revision 2332)
+++ time/strftime_l.c	(working copy)
@@ -883,7 +883,7 @@
 	    goto bad_format;
 	  if (modifier == L_('E'))
 	    {
-#if HAVE_STRUCT_ERA_ENTRY
+#if defined (OPTION_EGLIBC_LOCALE_CODE) && HAVE_STRUCT_ERA_ENTRY
 	      struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG);
 	      if (era)
 		{
@@ -956,7 +956,7 @@
 
 	  if (modifier == L_('O') && 0 <= number_value)
 	    {
-#ifdef _NL_CURRENT
+#if defined (OPTION_EGLIBC_LOCALE_CODE) && defined (_NL_CURRENT)
 	      /* Get the locale specific alternate representation of
 		 the number NUMBER_VALUE.  If none exist NULL is returned.  */
 	      const CHAR_T *cp = nl_get_alt_digit (number_value
@@ -1261,7 +1261,7 @@
 	case L_('Y'):
 	  if (modifier == 'E')
 	    {
-#if HAVE_STRUCT_ERA_ENTRY
+#if defined (OPTION_EGLIBC_LOCALE_CODE) && HAVE_STRUCT_ERA_ENTRY
 	      struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG);
 	      if (era)
 		{
@@ -1286,7 +1286,7 @@
 	case L_('y'):
 	  if (modifier == L_('E'))
 	    {
-#if HAVE_STRUCT_ERA_ENTRY
+#if defined (OPTION_EGLIBC_LOCALE_CODE) && HAVE_STRUCT_ERA_ENTRY
 	      struct era_entry *era = _nl_get_era_entry (tp HELPER_LOCALE_ARG);
 	      if (era)
 		{
Index: time/strptime_l.c
===================================================================
--- time/strptime_l.c	(revision 2332)
+++ time/strptime_l.c	(working copy)
@@ -93,7 +93,7 @@
     if (val < from || val > to)						      \
       return NULL;							      \
   } while (0)
-#ifdef _NL_CURRENT
+#if defined (OPTION_EGLIBC_LOCALE_CODE) && defined (_NL_CURRENT)
 # define get_alt_number(from, to, n) \
   ({									      \
      __label__ do_normal;						      \
@@ -760,6 +760,7 @@
 	      want_xday = 1;
 	      break;
 	    case 'C':
+#ifdef OPTION_EGLIBC_LOCALE_CODE
 	      if (*decided != raw)
 		{
 		  if (era_cnt >= 0)
@@ -796,10 +797,12 @@
 
 		  *decided = raw;
 		}
+#endif
 	      /* The C locale has no era information, so use the
 		 normal representation.  */
 	      goto match_century;
  	    case 'y':
+#ifdef OPTION_EGLIBC_LOCALE_CODE
 	      if (*decided != raw)
 		{
 		  get_number(0, 9999, 4);
@@ -858,9 +861,10 @@
 
 		  *decided = raw;
 		}
-
+#endif
 	      goto match_year_in_century;
 	    case 'Y':
+#ifdef OPTION_EGLIBC_LOCALE_CODE
 	      if (*decided != raw)
 		{
 		  num_eras = _NL_CURRENT_WORD (LC_TIME,
@@ -889,6 +893,7 @@
 
 		  *decided = raw;
 		}
+#endif
 	      get_number (0, 9999, 4);
 	      tm->tm_year = val - 1900;
 	      want_century = 0;
@@ -1050,6 +1055,7 @@
 	tm->tm_year = (century - 19) * 100;
     }
 
+#ifdef OPTION_EGLIBC_LOCALE_CODE
   if (era_cnt != -1)
     {
       era = _nl_select_era_entry (era_cnt HELPER_LOCALE_ARG);
@@ -1064,6 +1070,7 @@
 	tm->tm_year = era->start_date[0];
     }
   else
+#endif
     if (want_era)
       {
 	/* No era found but we have seen an E modifier.  Rectify some
Index: libio/Makefile
===================================================================
--- libio/Makefile	(revision 2332)
+++ libio/Makefile	(working copy)
@@ -49,7 +49,7 @@
 
 tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc   \
 	tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-fopenloc	      \
-	tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf tst-sscanf	      \
+	tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-sscanf	      \
 	tst-mmap-setvbuf bug-ungetwc1 bug-ungetwc2 tst-atime tst-eof          \
 	tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \
 	tst-mmap-eofsync tst-mmap-fflushsync bug-mmap-fflush \
@@ -59,6 +59,8 @@
 	tst-wmemstream1 tst-wmemstream2 \
 	bug-memstream1 bug-wmemstream1 \
 	tst-setvbuf1
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+     += tst-swscanf
 test-srcs = test-freopen
 
 all: # Make this the default target; it will be defined in Rules.
Index: intl/dcigettext.c
===================================================================
--- intl/dcigettext.c	(revision 2332)
+++ intl/dcigettext.c	(working copy)
@@ -464,7 +464,11 @@
   search->category = category;
 # ifdef HAVE_PER_THREAD_LOCALE
 #  ifdef _LIBC
+#   ifdef OPTION_EGLIBC_LOCALE_CODE
   localename = __current_locale_name (category);
+#   else
+  localename = "C";
+#   endif
 #  endif
   search->localename = localename;
 # endif
@@ -1302,7 +1306,11 @@
      `LC_xxx', and `LANG'.  On some systems this can be done by the
      `setlocale' function itself.  */
 #ifdef _LIBC
+# ifdef OPTION_EGLIBC_LOCALE_CODE
   retval = __current_locale_name (category);
+# else
+  retval = "C";
+# endif
 #else
   retval = _nl_locale_name (category, categoryname);
 #endif
Index: intl/Makefile
===================================================================
--- intl/Makefile	(revision 2332)
+++ intl/Makefile	(working copy)
@@ -17,6 +17,7 @@
 # 02111-1307 USA.
 
 # Makefile for intl subdirectory: message handling code from GNU gettext.
+include ../option-groups.mak
 
 subdir = intl
 headers = libintl.h
@@ -62,7 +63,7 @@
 include ../Rules
 
 # eglibc: ifeq (no,$(cross-compiling))
-ifeq (yes,$(build-shared))
+ifeq (yyes,$(OPTION_EGLIBC_LOCALES)$(build-shared))
 ifneq ($(strip $(MSGFMT)),:)
 tests: $(objpfx)tst-translit.out $(objpfx)tst-gettext2.out \
        $(objpfx)tst-codeset.out $(objpfx)tst-gettext3.out
@@ -101,6 +102,11 @@
 	$(make-target-directory)
 	LC_ALL=C sed -f $^ > $@
 
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+
+CFLAGS-dcigettext.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+
 CFLAGS-tst-gettext.c = -DTESTSTRS_H=\"$(objpfx)msgs.h\"
 CFLAGS-tst-translit.c = -DOBJPFX=\"$(objpfx)\"
 CFLAGS-tst-gettext2.c = -DOBJPFX=\"$(objpfx)\"
Index: localedata/Makefile
===================================================================
--- localedata/Makefile	(revision 2332)
+++ localedata/Makefile	(working copy)
@@ -102,10 +102,14 @@
 		     tst_wcsxfrm tst_wctob tst_wctomb tst_wctrans      \
 		     tst_wctype tst_wcwidth
 
-tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \
+# Since these tests build their own locale files, they're not
+# dependent on the OPTION_EGLIBC_LOCALES option group.  But they do
+# need the locale functions to be present.
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+     += $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \
 	tst-leaks tst-mbswcs6 tst-xlocale1 tst-xlocale2 bug-usesetlocale \
 	tst-strfmon1 tst-sscanf
-ifeq (yes,$(build-shared))
+ifeq (yesy,$(build-shared)$(OPTION_EGLIBC_LOCALE_CODE))
 ifneq (no,$(PERL))
 tests: $(objpfx)mtrace-tst-leaks
 endif
@@ -166,10 +170,12 @@
 $(addsuffix .out,$(addprefix $(objpfx),$(tests))): %: \
   $(addprefix $(objpfx),$(CTYPE_FILES))
 
+ifeq (y,$(OPTION_EGLIBC_LOCALE_CODE))
 tests: $(objpfx)sort-test.out $(objpfx)tst-fmon.out $(objpfx)tst-locale.out \
        $(objpfx)tst-rpmatch.out $(objpfx)tst-trans.out \
        $(objpfx)tst-mbswcs.out $(objpfx)tst-ctype.out $(objpfx)tst-wctype.out \
        $(objpfx)tst-langinfo.out $(objpfx)tst-numeric.out
+endif
 
 $(objpfx)sort-test.out: sort-test.sh $(objpfx)collate-test $(objpfx)xfrm-test \
 		       $(test-input-data) $(addprefix $(objpfx),$(CTYPE_FILES))
Index: string/Makefile
===================================================================
--- string/Makefile	(revision 2332)
+++ string/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Sub-makefile for string portion of library.
 #
+include ../option-groups.mak
+
 subdir	:= string
 
 headers	:= string.h strings.h memory.h endian.h bits/endian.h \
@@ -52,14 +54,21 @@
 tests		:= tester inl-tester noinl-tester testcopy test-ffs	\
 		   tst-strlen stratcliff tst-svc tst-inlcall		\
 		   bug-strncat1 bug-strspn1 bug-strpbrk1 tst-bswap	\
-		   tst-strtok tst-strxfrm bug-strcoll1 tst-strfry	\
+		   tst-strtok tst-strfry	\
 		   bug-strtok1 $(addprefix test-,$(strop-tests))	\
 		   bug-envz1 tst-strxfrm2
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+		+= tst-strxfrm bug-strcoll1
 distribute	:= memcopy.h pagecopy.h tst-svc.expect test-string.h
 
 
 include ../Rules
 
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+
+CFLAGS-strerror_l.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+
 tester-ENV = LANGUAGE=C
 inl-tester-ENV = LANGUAGE=C
 noinl-tester-ENV = LANGUAGE=C
Index: string/strerror_l.c
===================================================================
--- string/strerror_l.c	(revision 2332)
+++ string/strerror_l.c	(working copy)
@@ -30,10 +30,14 @@
 static const char *
 translate (const char *str, locale_t loc)
 {
+#ifdef OPTION_EGLIBC_LOCALE_CODE
   locale_t oldloc = __uselocale (loc);
   const char *res = _(str);
   __uselocale (oldloc);
   return res;
+#else
+  return str;
+#endif
 }
 
 
Index: iconv/gconv_db.c
===================================================================
--- iconv/gconv_db.c	(revision 2332)
+++ iconv/gconv_db.c	(working copy)
@@ -826,9 +826,11 @@
 /* Free all resources if necessary.  */
 libc_freeres_fn (free_mem)
 {
+#ifdef OPTION_EGLIBC_LOCALE_CODE
   /* First free locale memory.  This needs to be done before freeing derivations,
      as ctype cleanup functions dereference steps arrays which we free below.  */
   _nl_locale_subfreeres ();
+#endif
 
   /* finddomain.c has similar problem.  */
   extern void _nl_finddomain_subfreeres (void) attribute_hidden;
Index: iconv/Makefile
===================================================================
--- iconv/Makefile	(revision 2332)
+++ iconv/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Makefile for iconv.
 #
+include ../option-groups.mak
+
 subdir	:= iconv
 
 include ../Makeconfig
@@ -35,13 +37,19 @@
 CFLAGS-gconv_simple.c = -DSTATIC_GCONV
 endif
 
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+
+CFLAGS-gconv_db.c += $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+
 vpath %.c ../locale/programs ../intl
 
 iconv_prog-modules = iconv_charmap charmap charmap-dir linereader \
 		     dummy-repertoire simple-hash xstrdup xmalloc
 iconvconfig-modules = strtab xmalloc hash-string
 extra-objs	   = $(iconv_prog-modules:=.o) $(iconvconfig-modules:=.o)
-CFLAGS-iconv_prog.c = -I../locale/programs
+CFLAGS-iconv_prog.c = -I../locale/programs \
+		      $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
 CFLAGS-iconv_charmap.c = -I../locale/programs
 CFLAGS-dummy-repertoire.c = -I../locale/programs
 CFLAGS-charmap.c = -DCHARMAP_PATH='"$(i18ndir)/charmaps"' \
Index: iconv/iconv_prog.c
===================================================================
--- iconv/iconv_prog.c	(revision 2332)
+++ iconv/iconv_prog.c	(working copy)
@@ -229,10 +229,17 @@
 	      bool to_wrong =
 		(iconv_open (to_code, "UTF-8") == (iconv_t) -1
 		 && errno == EINVAL);
+#ifdef OPTION_EGLIBC_LOCALE_CODE
 	      const char *from_pretty =
 		(from_code[0] ? from_code : nl_langinfo (CODESET));
 	      const char *to_pretty =
 		(orig_to_code[0] ? orig_to_code : nl_langinfo (CODESET));
+#else
+	      const char *from_pretty =
+		(from_code[0] ? from_code : "ANSI_X3.4-1968");
+	      const char *to_pretty =
+                 (orig_to_code[0] ? orig_to_code : "ANSI_X3.4-1968");
+#endif
 
 	      if (from_wrong)
 		{
Index: locale/xlocale.c
===================================================================
--- locale/xlocale.c	(revision 2332)
+++ locale/xlocale.c	(working copy)
@@ -26,6 +26,19 @@
 #include "categories.def"
 #undef	DEFINE_CATEGORY
 
+/* If the locale support code isn't enabled, don't generate strong
+   reference to the C locale_data structures here; let the Makefile
+   decide which ones to include.  (In the static linking case, the
+   strong reference to the 'class', 'toupper', and 'tolower' tables
+   will cause C-ctype.o to be brought in, as it should be, even when
+   the reference to _nl_C_LC_CTYPE will be weak.)  */
+#ifndef OPTION_EGLIBC_LOCALE_CODE
+# define DEFINE_CATEGORY(category, category_name, items, a) \
+  weak_extern (_nl_C_##category)
+# include "categories.def"
+# undef	DEFINE_CATEGORY
+#endif
+ 
 /* Defined in locale/C-ctype.c.  */
 extern const char _nl_C_LC_CTYPE_class[] attribute_hidden;
 extern const char _nl_C_LC_CTYPE_toupper[] attribute_hidden;
@@ -53,3 +66,26 @@
     .__ctype_tolower = (const int *) _nl_C_LC_CTYPE_tolower + 128,
     .__ctype_toupper = (const int *) _nl_C_LC_CTYPE_toupper + 128
   };
+
+
+#ifndef OPTION_EGLIBC_LOCALE_CODE
+/* When locale code is enabled, these are each defined in the
+   appropriate lc-CATEGORY.c file, so that static links (when __thread
+   is supported) bring in only those lc-CATEGORY.o files for
+   categories the program actually uses; look for NL_CURRENT_INDIRECT
+   in localeinfo.h.
+
+   When locale code is disabled, the _nl_C_CATEGORY objects are the
+   only possible referents.  At the moment, there isn't a way to get
+   OPTION_EGLIBC_LOCALE_CODE defined in every compilation unit that
+   #includes localeinfo.h, so we can't just turn off
+   NL_CURRENT_INDIRECT.  So we'll define the _nl_current_CATEGORY
+   pointers here.  */
+#if defined (NL_CURRENT_INDIRECT)
+#define DEFINE_CATEGORY(category, category_name, items, a)      \
+  __thread struct locale_data * const *_nl_current_##category   \
+  attribute_hidden = &_nl_C_locobj.__locales[category];
+#include "categories.def"
+#undef DEFINE_CATEGORY
+#endif
+#endif /* OPTION_EGLIBC_LOCALE_CODE */
Index: locale/Makefile
===================================================================
--- locale/Makefile	(revision 2332)
+++ locale/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Makefile for locales.
 #
+include ../option-groups.mak
+
 subdir	:= locale
 
 headers		= locale.h bits/locale.h langinfo.h xlocale.h
@@ -26,7 +28,7 @@
 		  iso-4217.def weight.h weightwc.h strlen-hash.h elem-hash.h \
 		  indigits.h indigitswc.h outdigits.h outdigitswc.h \
 		  coll-lookup.h C-translit.h.in C-translit.h gen-translit.pl \
-		  locarchive.h hashval.h \
+		  locarchive.h hashval.h dummy-setlocale.c \
 		  $(addprefix programs/, \
 			      locale.c localedef.c \
 			      $(localedef-modules:=.c) $(locale-modules:=.c) \
@@ -35,22 +37,36 @@
 			      locfile-kw.gperf locfile-kw.h linereader.h \
 			      locfile.h charmap.h repertoire.h localedef.h \
 			      3level.h charmap-dir.h locarchive.c)
-routines	= setlocale findlocale loadlocale loadarchive \
-		  localeconv nl_langinfo nl_langinfo_l mb_cur_max \
-		  newlocale duplocale freelocale uselocale
-tests		= tst-C-locale
+# catnames is needed by OPTION_EGLIBC_LOCALE_CODE and by the 'intl' code.
+# If we put the latter in an option group, too, we can omit catnames
+# when both option groups are disabled.  libstdc++-v3 needs mb_cur_max.
+routines-y      := catnames mb_cur_max
+routines-$(OPTION_EGLIBC_LOCALE_CODE) \
+		+= setlocale findlocale loadlocale loadarchive \
+		   localeconv nl_langinfo nl_langinfo_l \
+		   newlocale duplocale freelocale uselocale
+ifneq (y,$(OPTION_EGLIBC_LOCALE_CODE))
+routines-y	+= dummy-setlocale
+endif
+tests-$(OPTION_EGLIBC_LOCALE_CODE) += tst-C-locale
 categories	= ctype messages monetary numeric time paper name \
 		  address telephone measurement identification collate
-aux		= $(categories:%=lc-%) $(categories:%=C-%) SYS_libc C_name \
-		  xlocale localename global-locale coll-lookup
-others		= localedef locale
+# C-messages belongs in an intl option group.
+aux-y		:= C-ctype C-time \
+		   SYS_libc C_name xlocale global-locale coll-lookup
+aux-$(OPTION_EGLIBC_LOCALE_CODE) \
+		+= $(filter-out $(aux-y), \
+	                        $(categories:%=lc-%) $(categories:%=C-%)) \
+	           localename
+others-$(OPTION_EGLIBC_LOCALE_CODE) = localedef locale
 #others-static	= localedef locale
-install-bin	= localedef locale
-extra-objs	= $(localedef-modules:=.o) $(localedef-aux:=.o) \
+install-bin	= $(others-y)
+extra-objs-$(OPTION_EGLIBC_LOCALE_CODE) \
+		= $(localedef-modules:=.o) $(localedef-aux:=.o) \
 		  $(locale-modules:=.o) $(lib-modules:=.o)
 
-extra-libs	= libBrokenLocale
-extra-libs-others = $(extra-libs)
+extra-libs-$(OPTION_EGLIBC_LOCALE_CODE) = libBrokenLocale
+extra-libs-others = $(extra-libs-y)
 
 libBrokenLocale-routines = broken_cur_max
 
@@ -98,6 +114,10 @@
 		   -DLOCSRCDIR='"$(i18ndir)/locales"' -DHAVE_CONFIG_H \
 		   -Iprograms
 
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+
+CFLAGS-xlocale.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
 CFLAGS-charmap.c = -Wno-write-strings -Wno-char-subscripts
 CFLAGS-locfile.c = -Wno-write-strings -Wno-char-subscripts
 CFLAGS-charmap-dir.c = -Wno-write-strings
Index: locale/catnames.c
===================================================================
--- locale/catnames.c	(revision 0)
+++ locale/catnames.c	(revision 0)
@@ -0,0 +1,48 @@
+/* Copyright (C) 2006  Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include "localeinfo.h"
+
+/* Define an array of category names (also the environment variable names).  */
+const union catnamestr_t _nl_category_names attribute_hidden =
+  {
+    {
+#define DEFINE_CATEGORY(category, category_name, items, a) \
+      category_name,
+#include "categories.def"
+#undef DEFINE_CATEGORY
+    }
+  };
+
+const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden =
+  {
+#define DEFINE_CATEGORY(category, category_name, items, a) \
+    [category] = offsetof (union catnamestr_t, CATNAMEMF (__LINE__)),
+#include "categories.def"
+#undef DEFINE_CATEGORY
+  };
+
+/* An array of their lengths, for convenience.  */
+const uint8_t _nl_category_name_sizes[] attribute_hidden =
+  {
+#define DEFINE_CATEGORY(category, category_name, items, a) \
+    [category] = sizeof (category_name) - 1,
+#include "categories.def"
+#undef	DEFINE_CATEGORY
+    [LC_ALL] = sizeof ("LC_ALL") - 1
+  };
Index: locale/dummy-setlocale.c
===================================================================
--- locale/dummy-setlocale.c	(revision 0)
+++ locale/dummy-setlocale.c	(revision 0)
@@ -0,0 +1,33 @@
+/* Copyright (C) 2006  Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <string.h>
+#include <locale.h>
+
+char *
+setlocale (int category, const char *locale)
+{
+  if (! locale
+      || locale[0] == '\0'
+      || strcmp (locale, "C") == 0
+      || strcmp (locale, "POSIX") == 0)
+    return (char *) "C";
+  else
+    return NULL;
+}
+libc_hidden_def (setlocale)
Index: locale/setlocale.c
===================================================================
--- locale/setlocale.c	(revision 2332)
+++ locale/setlocale.c	(working copy)
@@ -66,36 +66,6 @@
 #endif
 
 
-/* Define an array of category names (also the environment variable names).  */
-const union catnamestr_t _nl_category_names attribute_hidden =
-  {
-    {
-#define DEFINE_CATEGORY(category, category_name, items, a) \
-      category_name,
-#include "categories.def"
-#undef DEFINE_CATEGORY
-    }
-  };
-
-const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden =
-  {
-#define DEFINE_CATEGORY(category, category_name, items, a) \
-    [category] = offsetof (union catnamestr_t, CATNAMEMF (__LINE__)),
-#include "categories.def"
-#undef DEFINE_CATEGORY
-  };
-
-/* An array of their lengths, for convenience.  */
-const uint8_t _nl_category_name_sizes[] attribute_hidden =
-  {
-#define DEFINE_CATEGORY(category, category_name, items, a) \
-    [category] = sizeof (category_name) - 1,
-#include "categories.def"
-#undef	DEFINE_CATEGORY
-    [LC_ALL] = sizeof ("LC_ALL") - 1
-  };
-
-
 #ifdef NL_CURRENT_INDIRECT
 # define WEAK_POSTLOAD(postload) weak_extern (postload)
 #else
Index: Makerules
===================================================================
--- Makerules	(revision 2332)
+++ Makerules	(working copy)
@@ -406,18 +406,19 @@
 endif
 
 # Include targets in the selected option groups.
-aux		  += $(aux-y)
-extra-libs   	  += $(extra-libs-y)
-extra-libs-others += $(extra-libs-others-y)
-extra-objs   	  += $(extra-objs-y)
-install-bin  	  += $(install-bin-y)
-install-others    += $(install-others-y)
-install-sbin 	  += $(install-sbin-y)
-others       	  += $(others-y)
-routines     	  += $(routines-y)
-test-srcs    	  += $(test-srcs-y)
-tests        	  += $(tests-y)
-xtests       	  += $(xtests-y)
+aux		     += $(aux-y)
+extra-libs	     += $(extra-libs-y)
+extra-libs-others    += $(extra-libs-others-y)
+extra-objs	     += $(extra-objs-y)
+install-bin	     += $(install-bin-y)
+install-others	     += $(install-others-y)
+install-sbin	     += $(install-sbin-y)
+others		     += $(others-y)
+routines	     += $(routines-y)
+static-only-routines += $(static-only-routines-y)
+test-srcs	     += $(test-srcs-y)
+tests		     += $(tests-y)
+xtests		     += $(xtests-y)
 
 
 # Modify the list of routines we build for different targets
Index: option-groups.defaults
===================================================================
--- option-groups.defaults	(revision 2332)
+++ option-groups.defaults	(working copy)
@@ -10,5 +10,6 @@
 # By default, all option groups are enabled.
 OPTION_EGLIBC_CATGETS = y
 OPTION_EGLIBC_LOCALES = y
+OPTION_EGLIBC_LOCALE_CODE = y
 OPTION_EGLIBC_LIBM = y
 OPTION_EGLIBC_INET = y
Index: option-groups.def
===================================================================
--- option-groups.def	(revision 2332)
+++ option-groups.def	(working copy)
@@ -50,6 +50,25 @@
        that for the "C" locale.  If this option group is omitted, then
        only the "C" locale is supported.
 
+
+config OPTION_EGLIBC_LOCALE_CODE
+   bool "Locale functions"
+   help
+       This option group includes locale support functions, programs,
+       and libraries.  With OPTION_EGLIBC_LOCALE_FUNCTIONS disabled,
+       EGLIBC supports only the 'C' locale (also known as 'POSIX'),
+       and ignores the settings of the 'LANG' and 'LC_*' environment
+       variables.
+
+       With OPTION_EGLIBC_LOCALE_CODE disabled, the following
+       functions are omitted from libc:
+
+         duplocale   localeconv  nl_langinfo    rpmatch  strfmon_l
+         freelocale  newlocale   nl_langinfo_l  strfmon  uselocale
+
+       Furthermore, only the LC_CTYPE and LC_TIME categories of the
+       standard "C" locale are available.
+
 config OPTION_EGLIBC_LIBM
    bool "libm (math library)"
    help
Index: posix/Makefile
===================================================================
--- posix/Makefile	(revision 2332)
+++ posix/Makefile	(working copy)
@@ -78,14 +78,14 @@
 tests		:= tstgetopt testfnm runtests runptests	     \
 		   tst-preadwrite tst-preadwrite64 test-vfork regexbug1 \
 		   tst-getlogin tst-mmap tst-truncate \
-		   tst-truncate64 tst-fork tst-fnmatch tst-regexloc tst-dir \
-		   tst-chmod bug-regex1 bug-regex2 bug-regex3 bug-regex4 \
-		   tst-gnuglob tst-regex bug-regex5 bug-regex6 bug-regex7 \
+		   tst-truncate64 tst-fork tst-dir \
+		   tst-chmod bug-regex2 bug-regex3 bug-regex4 \
+		   tst-gnuglob bug-regex6 bug-regex7 \
 		   bug-regex8 bug-regex9 bug-regex10 bug-regex11 bug-regex12 \
 		   bug-regex13 bug-regex14 bug-regex15 bug-regex16 \
-		   bug-regex17 bug-regex18 bug-regex19 bug-regex20 \
-		   bug-regex21 bug-regex22 bug-regex23 bug-regex24 \
-		   bug-regex25 bug-regex26 bug-regex27 bug-regex28 \
+		   bug-regex17 bug-regex18 bug-regex20 \
+		   bug-regex21 bug-regex23 bug-regex24 \
+		   bug-regex26 bug-regex27 bug-regex28 \
 		   tst-nice tst-nanosleep tst-regex2 \
 		   transbug tst-rxspencer tst-pcre tst-boost \
 		   tst-vfork1 tst-vfork2 tst-vfork3 tst-waitid \
@@ -95,6 +95,9 @@
 		   tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
 		   tst-execvp3 tst-execvp4 \
 		   tst-fnmatch2 tst-cpucount
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+		+= tst-fnmatch tst-regex tst-regexloc bug-regex1 bug-regex5 \
+		   bug-regex19 bug-regex22 bug-regex25
 tests-$(OPTION_EGLIBC_INET) \
 	        += tst-getaddrinfo bug-ga1 tst-getaddrinfo2 \
 		   tst-rfc3484 tst-rfc3484-2 tst-getaddrinfo3
Index: stdio-common/printf_fp.c
===================================================================
--- stdio-common/printf_fp.c	(revision 2332)
+++ stdio-common/printf_fp.c	(working copy)
@@ -262,6 +262,7 @@
 
 
   /* Figure out the decimal point character.  */
+#ifdef OPTION_EGLIBC_LOCALE_CODE
   if (info->extra == 0)
     {
       decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
@@ -281,7 +282,13 @@
   /* The decimal point character must not be zero.  */
   assert (*decimal != '\0');
   assert (decimalwc != L'\0');
+#else
+  /* Hard-code values from 'C' locale.  */
+  decimal = ".";
+  decimalwc = L'.';
+#endif
 
+#ifdef OPTION_EGLIBC_LOCALE_CODE
   if (info->group)
     {
       if (info->extra == 0)
@@ -325,6 +332,9 @@
     }
   else
     grouping = NULL;
+#else
+  grouping = NULL;
+#endif
 
   /* Fetch the argument value.	*/
 #ifndef __NO_LONG_DOUBLE_MATH
Index: stdio-common/printf_fphex.c
===================================================================
--- stdio-common/printf_fphex.c	(revision 2332)
+++ stdio-common/printf_fphex.c	(working copy)
@@ -148,6 +148,7 @@
 
 
   /* Figure out the decimal point character.  */
+#ifdef OPTION_EGLIBC_LOCALE_CODE
   if (info->extra == 0)
     {
       decimal = _NL_CURRENT (LC_NUMERIC, DECIMAL_POINT);
@@ -161,6 +162,10 @@
     }
   /* The decimal point character must never be zero.  */
   assert (*decimal != '\0' && decimalwc != L'\0');
+#else
+  decimal = ".";
+  decimalwc = L'.';
+#endif
 
 
   /* Fetch the argument value.	*/
Index: stdio-common/Makefile
===================================================================
--- stdio-common/Makefile	(revision 2332)
+++ stdio-common/Makefile	(working copy)
@@ -19,6 +19,8 @@
 #
 #	Specific makefile for stdio-common.
 #
+include ../option-groups.mak
+
 subdir	:= stdio-common
 
 headers	:= stdio_ext.h printf.h bits/printf-ldbl.h
@@ -50,11 +52,13 @@
 	 bug1 bug2 bug3 bug4 bug5 bug6 bug7 bug8 bug9 bug10 bug11 bug12 bug13 \
 	 tfformat tiformat tllformat tstdiomisc tst-printfsz tst-wc-printf \
 	 scanf1 scanf2 scanf3 scanf4 scanf5 scanf7 scanf8 scanf9 scanf10 \
-	 scanf11 scanf12 tst-tmpnam tst-cookie tst-obprintf tst-sscanf \
-	 tst-swprintf tst-fseek tst-fmemopen test-vfprintf tst-gets \
-	 tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 bug15 \
+	 scanf11 scanf12 tst-tmpnam tst-cookie tst-obprintf \
+	 tst-fseek tst-fmemopen tst-gets \
+	 tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 \
 	 tst-popen tst-unlockedio tst-fmemopen2 tst-put-error tst-fgets \
 	 tst-fwrite bug16 bug17 tst-swscanf
+tests-$(OPTION_EGLIBC_LOCALE_CODE) \
+      += tst-sscanf tst-swprintf bug15 test-vfprintf
 
 test-srcs = tst-unbputc tst-printf
 
@@ -76,12 +80,17 @@
 	$(SHELL) -e tst-printf.sh $(common-objpfx) '$(run-program-prefix)'
 # eglibc: endif
 
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+
 CFLAGS-vfprintf.c = -Wno-uninitialized
 CFLAGS-tst-printf.c = -Wno-format
 CFLAGS-tstdiomisc.c = -Wno-format
 CFLAGS-scanf4.c = -Wno-format
 CFLAGS-scanf7.c = -Wno-format
 CFLAGS-tst-printfsz.c = -Wno-format
+CFLAGS-printf_fp.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
+CFLAGS-printf_fphex.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)
 
 CFLAGS-tmpfile.c = -fexceptions
 CFLAGS-tmpfile64.c = -fexceptions
Index: libidn/toutf8.c
===================================================================
--- libidn/toutf8.c	(revision 2332)
+++ libidn/toutf8.c	(working copy)
@@ -49,7 +49,11 @@
 #endif
 
 #ifdef _LIBC
-# define stringprep_locale_charset() nl_langinfo (CODESET)
+# ifdef OPTION_EGLIBC_LOCALE_CODE
+#  define stringprep_locale_charset() nl_langinfo (CODESET)
+# else
+#  define stringprep_locale_charset() "ANSI_X3.4-1968"
+# endif
 #else
 /**
  * stringprep_locale_charset - return charset used in current locale
Index: libidn/Makefile
===================================================================
--- libidn/Makefile	(revision 2332)
+++ libidn/Makefile	(working copy)
@@ -17,6 +17,7 @@
 # 02111-1307 USA.
 
 # Makefile for libidn subdirectory of GNU C Library.
+include ../option-groups.mak
 
 subdir	:= libidn
 
@@ -38,3 +39,8 @@
 include $(..)Rules
 
 $(objpfx)libcidn.so: $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
+
+OPTION_EGLIBC_LOCALE_CODE-CFLAGS-$(OPTION_EGLIBC_LOCALE_CODE) \
+	= -DOPTION_EGLIBC_LOCALE_CODE
+
+CFLAGS-toutf8.c = $(OPTION_EGLIBC_LOCALE_CODE-CFLAGS-y)