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

[commits] r13954 - in /trunk/libc: ./ elf/ grp/ iconvdata/ include/ libio/ locale/ localedata/ math/ nis/nss_nis/ nscd/ posix/ stdio-c...



Author: joseph
Date: Mon May 23 12:23:42 2011
New Revision: 13954

Log:
Merge changes between r13882 and r13953 from /fsf/trunk.

Added:
    trunk/libc/localedata/bug-setlocale1.c
      - copied unchanged from r13953, fsf/trunk/libc/localedata/bug-setlocale1.c
    trunk/libc/math/test-powl.c
      - copied unchanged from r13953, fsf/trunk/libc/math/test-powl.c
Modified:
    trunk/libc/ChangeLog
    trunk/libc/NEWS
    trunk/libc/configure
    trunk/libc/configure.in
    trunk/libc/elf/dl-runtime.c
    trunk/libc/grp/compat-initgroups.c
    trunk/libc/iconvdata/CP1258.irreversible
    trunk/libc/iconvdata/cp1258.c
    trunk/libc/include/alloca.h
    trunk/libc/libio/filedoalloc.c
    trunk/libc/libio/freopen.c
    trunk/libc/libio/freopen64.c
    trunk/libc/locale/setlocale.c
    trunk/libc/localedata/ChangeLog
    trunk/libc/localedata/Makefile
    trunk/libc/math/Makefile
    trunk/libc/nis/nss_nis/nis-alias.c
    trunk/libc/nscd/nscd_getserv_r.c
    trunk/libc/posix/glob.c
    trunk/libc/posix/regex.h
    trunk/libc/stdio-common/perror.c
    trunk/libc/stdio-common/vfprintf.c
    trunk/libc/stdlib/longlong.h
    trunk/libc/string/_strerror.c
    trunk/libc/string/xpg-strerror.c
    trunk/libc/sysdeps/posix/getaddrinfo.c
    trunk/libc/sysdeps/powerpc/powerpc64/Makefile
    trunk/libc/sysdeps/unix/sysv/linux/bits/time.h
    trunk/libc/sysdeps/unix/sysv/linux/ia64/sysconf.c
    trunk/libc/sysdeps/unix/sysv/linux/sysconf.c
    trunk/libc/sysdeps/x86_64/fpu/e_powl.S

Modified: trunk/libc/ChangeLog
==============================================================================
--- trunk/libc/ChangeLog (original)
+++ trunk/libc/ChangeLog Mon May 23 12:23:42 2011
@@ -1,3 +1,97 @@
+2011-05-20  Andreas Schwab  <schwab@xxxxxxxxxx>
+
+	* stdlib/longlong.h: Update from GCC.
+
+2011-05-23  Andreas Schwab  <schwab@xxxxxxxxxx>
+
+	* sysdeps/unix/sysv/linux/ia64/sysconf.c (HAS_CPUCLOCK): Add
+	parameter name.
+	* sysdeps/unix/sysv/linux/sysconf.c (has_cpuclock, HAS_CPUCLOCK):
+	Add parameter name.
+	(__sysconf): Pass it down.
+
+2011-05-22  Ulrich Drepper  <drepper@xxxxxxxxx>
+
+	[BZ #12671]
+	* nis/nss_nis/nis-alias.c (_nss_nis_getaliasbyname_r): Use malloc in
+	some situations.
+	* nscd/nscd_getserv_r.c (nscd_getserv_r): Likewise.
+	* posix/glob.c (glob_in_dir): Take additional parameter alloca_used.
+	add in in __libc_use_alloca calls.  Adjust callers.
+	(glob): Use malloc in some situations.
+
+	* elf/dl-runtime.c (_dl_profile_fixup): Also store LA_SYMB_NOPLTENTER
+	and LA_SYMB_NOPLTEXIT in flags which are passed to pltenter and
+	pltexit.
+
+2011-05-21  Ulrich Drepper  <drepper@xxxxxxxxx>
+
+	* sysdeps/unix/sysv/linux/bits/time.h: Define CLOCK_REALTIME_ALARM
+	and CLOCK_BOOTTIME_ALARM.
+
+	[BZ #12782]
+	* string/xpg-strerror.c (__xpg_strerror_r): Fill buffer even if error
+	is returned.
+
+	* string/_strerror.c (__strerror_r): Print negative errors as signed
+	numbers.
+
+	[BZ #12777]
+	* iconvdata/cp1258.c (comp_table_data): Remove entry 0x00A5 0xEC.
+	(decomp_table): Change U0385 entry to emit 0xA5 0xEC.
+	* iconvdata/CP1258.irreversible: Adjust entry 0xA8EC.
+
+	* configure.in: Fix typo in redirection and correct removal of test
+	files in two cases.
+
+	[BZ #12788]
+	* locale/setlocale.c (new_composite_name): Fix test to check for
+	identical name of all categories.
+
+	[BZ #12792]
+	* libio/filedoalloc.c (local_isatty): New function.
+	(_IO_file_doallocate): Use local_isatty.
+	* stdio-common/perror.c (perror): In case a new stream is used
+	forward the stream error.
+	* stdio-common/vfprintf.c (ARGCHECK): For read-only streams also set
+	error flag.
+
+2011-05-20  Ulrich Drepper  <drepper@xxxxxxxxx>
+
+	[BZ #11869]
+	* sysdeps/posix/getaddrinfo.c (gaih_inet): Don't unconditionally use
+	alloca.
+	* include/alloca.h (extend_alloca_account): Define.
+
+	[BZ #11857]
+	* posix/regex.h: Fix comments with documentation of user-accessible
+	fields after compilation and describe correct free'ing of pattern
+	after re_compile_pattern.
+	Patch by Reuben Thomas <rrt@xxxxxxxx>.
+
+2011-05-18  Ryan S. Arnold  <rsa@xxxxxxxxxx>
+
+	* sysdeps/powerpc/powerpc64/Makefile (no-special-regs): Add -mno-vsx
+	and -mno-altivec to prevent the compiler from using Altivec and/or
+	VSX instructions when the corresponding registers are not available.
+
+2011-05-19  Andreas Schwab  <schwab@xxxxxxxxxx>
+
+	* grp/compat-initgroups.c (__libc_use_alloca): Don't define.
+
+2011-05-19  Ulrich Drepper  <drepper@xxxxxxxxx>
+
+	* libio/freopen.c (freopen): Use __dup2, not dup2.
+	* libio/freopen64.c (freopen64): Likewise.
+
+2011-05-17  H.J. Lu  <hongjiu.lu@xxxxxxxxx>
+
+	[BZ #12775]
+	* sysdeps/x86_64/fpu/e_powl.S: Fix a typo.
+	* math/Makefile (tests): Add test-powl.
+	(CFLAGS-test-powl.c): Define.
+	* math/test-powl.c: New file.
+
 2011-05-16  H.J. Lu  <hongjiu.lu@xxxxxxxxx>
 
 	* fileops.c (_IO_new_file_fopen): Get fd from _IO_fileno.

Modified: trunk/libc/NEWS
==============================================================================
--- trunk/libc/NEWS (original)
+++ trunk/libc/NEWS Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-GNU C Library NEWS -- history of user-visible changes.  2011-5-17
+GNU C Library NEWS -- history of user-visible changes.  2011-5-22
 Copyright (C) 1992-2009, 2010, 2011 Free Software Foundation, Inc.
 See the end for copying conditions.
 
@@ -10,13 +10,14 @@
 * The following bugs are resolved with this release:
 
   386, 6420, 7101, 9730, 9732, 9809, 10138, 10149, 10157, 11257, 11258,
-  11487, 11532, 11578, 11653, 11668, 11697, 11724, 11820, 11837, 11892,
-  11895, 11901, 11945, 11947, 11952, 11987, 12052, 12083, 12158, 12178,
-  12200, 12346, 12393, 12420, 12432, 12445, 12449, 12453, 12454, 12460,
-  12469, 12489, 12509, 12510, 12511, 12518, 12527, 12541, 12545, 12551,
-  12582, 12583, 12587, 12597, 12601, 12611, 12625, 12626, 12631, 12650,
-  12653, 12655, 12660, 12681, 12685, 12711, 12713, 12714, 12717, 12723,
-  12724, 12734, 12738, 12746, 12766
+  11487, 11532, 11578, 11653, 11668, 11697, 11724, 11820, 11837, 11857,
+  11869, 11892, 11895, 11901, 11945, 11947, 11952, 11987, 12052, 12083,
+  12158, 12178, 12200, 12346, 12393, 12420, 12432, 12445, 12449, 12453,
+  12454, 12460, 12469, 12489, 12509, 12510, 12511, 12518, 12527, 12541,
+  12545, 12551, 12582, 12583, 12587, 12597, 12601, 12611, 12625, 12626,
+  12631, 12650, 12653, 12655, 12660, 12671, 12681, 12685, 12711, 12713,
+  12714, 12717, 12723, 12724, 12734, 12738, 12746, 12766, 12775, 12777,
+  12782, 12788, 12792
 
 * The RPC implementation in libc is obsoleted.  Old programs keep working
   but new programs cannot be linked with the routines in libc anymore.

Modified: trunk/libc/configure
==============================================================================
--- trunk/libc/configure (original)
+++ trunk/libc/configure Mon May 23 12:23:42 2011
@@ -6258,7 +6258,7 @@
 		      fi
 		    fi
 		  fi
-		  rm -f conftest.cs
+		  rm -f conftest.{c,s}
 
 fi
 { $as_echo "$as_me:$LINENO: result: $libc_cv_visibility_attribute" >&5
@@ -6282,7 +6282,7 @@
 		  int bar (int x) { return x; }
 EOF
 		  libc_cv_broken_visibility_attribute=yes
-		  if { ac_try='${CC-cc} -Werror -S conftest.c -o conftest.s1>&5'
+		  if { ac_try='${CC-cc} -Werror -S conftest.c -o conftest.s 1>&5'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
@@ -6942,7 +6942,7 @@
 		  else
 		    libc_cv_have_section_quotes=unknown
 		  fi
-		  rm -f conftest.cs
+		  rm -f conftest.{c,s}
 
 fi
 { $as_echo "$as_me:$LINENO: result: $libc_cv_have_section_quotes" >&5

Modified: trunk/libc/configure.in
==============================================================================
--- trunk/libc/configure.in (original)
+++ trunk/libc/configure.in Mon May 23 12:23:42 2011
@@ -1426,7 +1426,7 @@
 		      fi
 		    fi
 		  fi
-		  rm -f conftest.[cs]
+		  rm -f conftest.{c,s}
 		 ])
     if test $libc_cv_visibility_attribute != yes; then
       AC_MSG_ERROR(compiler support for visibility attribute is required)
@@ -1442,7 +1442,7 @@
 		  int bar (int x) { return x; }
 EOF
 		  libc_cv_broken_visibility_attribute=yes
-		  if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s1>&AS_MESSAGE_LOG_FD); then
+		  if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
 changequote(,)dnl
 		    if grep '\.hidden[ 	_]foo' conftest.s >/dev/null; then
 changequote([,])dnl
@@ -1830,7 +1830,7 @@
 		  else
 		    libc_cv_have_section_quotes=unknown
 		  fi
-		  rm -f conftest.[cs]
+		  rm -f conftest.{c,s}
 		 ])
   if test $libc_cv_have_section_quotes = yes; then
     AC_DEFINE(HAVE_SECTION_QUOTES)
@@ -2104,7 +2104,7 @@
 
 if test -n "$submachine"; then
   AC_CACHE_CHECK([for compiler option for CPU variant],
-  		 libc_cv_cc_submachine, [dnl
+		 libc_cv_cc_submachine, [dnl
   libc_cv_cc_submachine=no
   for opt in "-march=$submachine" "-mcpu=$submachine"; do
     if AC_TRY_COMMAND([${CC-cc} $opt -xc /dev/null -S -o /dev/null]); then

Modified: trunk/libc/elf/dl-runtime.c
==============================================================================
--- trunk/libc/elf/dl-runtime.c (original)
+++ trunk/libc/elf/dl-runtime.c Mon May 23 12:23:42 2011
@@ -271,7 +271,7 @@
 	     interested in auditing.  */
 	  if ((l->l_audit_any_plt | result->l_audit_any_plt) != 0)
 	    {
-	      unsigned int altvalue = 0;
+	      unsigned int flags = 0;
 	      struct audit_ifaces *afct = GLRO(dl_audit);
 	      /* Synthesize a symbol record where the st_value field is
 		 the result.  */
@@ -294,7 +294,6 @@
 		  if ((l->l_audit[cnt].bindflags & LA_FLG_BINDFROM) != 0
 		      && (result->l_audit[cnt].bindflags & LA_FLG_BINDTO) != 0)
 		    {
-		      unsigned int flags = altvalue;
 		      if (afct->symbind != NULL)
 			{
 			  uintptr_t new_value
@@ -305,7 +304,7 @@
 					     strtab2 + defsym->st_name);
 			  if (new_value != (uintptr_t) sym.st_value)
 			    {
-			      altvalue = LA_SYMB_ALTVALUE;
+			      flags |= LA_SYMB_ALTVALUE;
 			      sym.st_value = new_value;
 			    }
 			}
@@ -328,7 +327,7 @@
 		  afct = afct->next;
 		}
 
-	      reloc_result->flags = altvalue;
+	      reloc_result->flags = flags;
 	      value = DL_FIXUP_ADDR_VALUE (sym.st_value);
 	    }
 	  else
@@ -366,7 +365,7 @@
       const char *symname = strtab + sym.st_name;
 
       /* Keep track of overwritten addresses.  */
-      unsigned int altvalue = reloc_result->flags;
+      unsigned int flags = reloc_result->flags;
 
       struct audit_ifaces *afct = GLRO(dl_audit);
       for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt)
@@ -375,7 +374,6 @@
 	      && (reloc_result->enterexit
 		  & (LA_SYMB_NOPLTENTER << (2 * (cnt + 1)))) == 0)
 	    {
-	      unsigned int flags = altvalue;
 	      long int new_framesize = -1;
 	      uintptr_t new_value
 		= afct->ARCH_LA_PLTENTER (&sym, reloc_result->boundndx,
@@ -385,7 +383,7 @@
 					  &new_framesize);
 	      if (new_value != (uintptr_t) sym.st_value)
 		{
-		  altvalue = LA_SYMB_ALTVALUE;
+		  flags |= LA_SYMB_ALTVALUE;
 		  sym.st_value = new_value;
 		}
 

Modified: trunk/libc/grp/compat-initgroups.c
==============================================================================
--- trunk/libc/grp/compat-initgroups.c (original)
+++ trunk/libc/grp/compat-initgroups.c Mon May 23 12:23:42 2011
@@ -7,12 +7,6 @@
 /* Prototype for the setgrent functions we use here.  */
 typedef enum nss_status (*get_function) (struct group *, char *,
 					 size_t, int *);
-
-/* This file is also used in nscd where __libc_alloca_cutoff is not
-   available.  */
-#ifdef NOT_IN_libc
-# define __libc_use_alloca(size) ((size) < __MAX_ALLOCA_CUTOFF * 4)
-#endif
 
 
 static enum nss_status

Modified: trunk/libc/iconvdata/CP1258.irreversible
==============================================================================
--- trunk/libc/iconvdata/CP1258.irreversible (original)
+++ trunk/libc/iconvdata/CP1258.irreversible Mon May 23 12:23:42 2011
@@ -96,8 +96,8 @@
 0x79F2	0x1EF5
 0x7AEC	0x017A
 0x7AF2	0x1E93
-0xA5EC	0x0385
 0xA8CC	0x1FED
+0xA8EC	0x0385
 0xA8EC	0x1FEE
 0xC2CC	0x1EA6
 0xC2D2	0x1EA8

Modified: trunk/libc/iconvdata/cp1258.c
==============================================================================
--- trunk/libc/iconvdata/cp1258.c (original)
+++ trunk/libc/iconvdata/cp1258.c Mon May 23 12:23:42 2011
@@ -1,5 +1,5 @@
 /* Conversion from and to CP1258.
-   Copyright (C) 1998, 2001, 2002, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1998, 2001, 2002, 2004, 2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 1998,
    and Bruno Haible <haible@xxxxxxxxxxxxxx>, 2001.
@@ -92,7 +92,7 @@
     0x20AC,      0, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
     0x02C6, 0x2030,      0, 0x2039, 0x0152,      0,      0,      0,
     /* 0x90 */
-         0, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
+	 0, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
     0x02DC, 0x2122,      0, 0x203A, 0x0153,      0,      0, 0x0178,
     /* 0xA0 */
     0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
@@ -162,7 +162,7 @@
     { 0x01AF, 0x1EEA },
     { 0x01B0, 0x1EEB },
 #define COMP_TABLE_IDX_0301 (COMP_TABLE_IDX_0300 + COMP_TABLE_LEN_0300)
-#define COMP_TABLE_LEN_0301 60
+#define COMP_TABLE_LEN_0301 59
     { 0x0041, 0x00C1 },
     { 0x0043, 0x0106 },
     { 0x0045, 0x00C9 },
@@ -197,7 +197,7 @@
     { 0x0077, 0x1E83 },
     { 0x0079, 0x00FD },
     { 0x007A, 0x017A },
-    { 0x00A5, 0x0385 },
+    /* { 0x00A5, 0x0385 }, Wrong, A5 is Yen sign */
     { 0x00A8, 0x1FEE },
     { 0x00C2, 0x1EA4 },
     { 0x00C5, 0x01FA },
@@ -505,7 +505,7 @@
 static const unsigned char from_ucs4[] =
   {
 #define FROM_IDX_00 0
-                            0xc4, 0xc5, 0xc6, 0xc7, /* 0x00c4-0x00c7 */
+			    0xc4, 0xc5, 0xc6, 0xc7, /* 0x00c4-0x00c7 */
     0xc8, 0xc9, 0xca, 0xcb, 0x00, 0xcd, 0xce, 0xcf, /* 0x00c8-0x00cf */
     0x00, 0xd1, 0x00, 0xd3, 0xd4, 0x00, 0xd6, 0xd7, /* 0x00d0-0x00d7 */
     0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0x00, 0x00, 0xdf, /* 0x00d8-0x00df */
@@ -517,7 +517,7 @@
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0108-0x010f */
     0xd0, 0xf0,                                     /* 0x0110-0x0111 */
 #define FROM_IDX_01 (FROM_IDX_00 + 78)
-                0x8c, 0x9c, 0x00, 0x00, 0x00, 0x00, /* 0x0152-0x0157 */
+		0x8c, 0x9c, 0x00, 0x00, 0x00, 0x00, /* 0x0152-0x0157 */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0158-0x015f */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0160-0x0167 */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0168-0x016f */
@@ -531,7 +531,7 @@
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdd, /* 0x01a8-0x01af */
     0xfd,                                           /* 0x01b0-0x01b0 */
 #define FROM_IDX_02 (FROM_IDX_01 + 95)
-                                        0x88, 0x00, /* 0x02c6-0x02c7 */
+					0x88, 0x00, /* 0x02c6-0x02c7 */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02c8-0x02cf */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x02d0-0x02d7 */
     0x00, 0x00, 0x00, 0x00, 0x98,                   /* 0x02d8-0x02dc */
@@ -542,7 +542,7 @@
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x0318-0x031f */
     0x00, 0x00, 0x00, 0xf2,                         /* 0x0320-0x0323 */
 #define FROM_IDX_20 (FROM_IDX_03 + 36)
-                      0x96, 0x97, 0x00, 0x00, 0x00, /* 0x2013-0x2017 */
+		      0x96, 0x97, 0x00, 0x00, 0x00, /* 0x2013-0x2017 */
     0x91, 0x92, 0x82, 0x00, 0x93, 0x94, 0x84, 0x00, /* 0x2018-0x201f */
     0x86, 0x87, 0x95, 0x00, 0x00, 0x00, 0x85, 0x00, /* 0x2020-0x2027 */
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x2028-0x202f */
@@ -619,7 +619,7 @@
     { 0x01fd, 0xe6, 0xec },
     { 0x01fe, 0xd8, 0xec },
     { 0x01ff, 0xf8, 0xec },
-    { 0x0385, 0xa5, 0xec },
+    { 0x0385, 0xa8, 0xec },
     { 0x1e04, 0x42, 0xf2 },
     { 0x1e05, 0x62, 0xf2 },
     { 0x1e08, 0xc7, 0xec },

Modified: trunk/libc/include/alloca.h
==============================================================================
--- trunk/libc/include/alloca.h (original)
+++ trunk/libc/include/alloca.h Mon May 23 12:23:42 2011
@@ -49,15 +49,24 @@
 
 #if defined stackinfo_get_sp && defined stackinfo_sub_sp
 # define alloca_account(size, avar) \
-  ({ void *old__ = stackinfo_get_sp ();			\
-     void *m__ = __alloca (size);			\
-     avar += stackinfo_sub_sp (old__);			\
+  ({ void *old__ = stackinfo_get_sp ();					      \
+     void *m__ = __alloca (size);					      \
+     avar += stackinfo_sub_sp (old__);					      \
+     m__; })
+# define extend_alloca_account(buf, len, newlen, avar) \
+  ({ void *old__ = stackinfo_get_sp ();					      \
+     void *m__ = extend_alloca (buf, len, newlen);			      \
+     avar += stackinfo_sub_sp (old__);					      \
      m__; })
 #else
 # define alloca_account(size, avar) \
-  ({ size_t s__ = (size);		    \
-     avar += s__;			    \
+  ({ size_t s__ = (size);						      \
+     avar += s__;							      \
      __alloca (s__); })
+# define extend_alloca_account(buf, len, newlen, avar) \
+  ({ size_t s__ = (newlen);						      \
+     avar += s__;							      \
+     extend_alloca (buf, len, s__); })
 #endif
 
 #endif

Modified: trunk/libc/libio/filedoalloc.c
==============================================================================
--- trunk/libc/libio/filedoalloc.c (original)
+++ trunk/libc/libio/filedoalloc.c Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1997, 2001, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1997, 2001, 2002, 2011 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
@@ -41,7 +41,7 @@
    4. Neither the name of the University nor the names of its contributors
       may be used to endorse or promote products derived from this software
       without specific prior written permission.
-   
+
    THIS SOFTWARE IS PROVIDED BY THE REGENTS 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
@@ -73,6 +73,17 @@
 
 # include <device-nrs.h>
 #endif
+
+
+static int
+local_isatty (int fd)
+{
+  int save_errno = errno;
+  int res = isatty (fd);
+  __set_errno (save_errno);
+  return res;
+}
+
 
 /*
  * Allocate a file buffer, or switch to unbuffered I/O.
@@ -109,7 +120,7 @@
 #ifdef DEV_TTY_P
 	      DEV_TTY_P (&st) ||
 #endif
-	      isatty (fp->_fileno))
+	      local_isatty (fp->_fileno))
 	    fp->_flags |= _IO_LINE_BUF;
 	}
 #if _IO_HAVE_ST_BLKSIZE

Modified: trunk/libc/libio/freopen.c
==============================================================================
--- trunk/libc/libio/freopen.c (original)
+++ trunk/libc/libio/freopen.c Mon May 23 12:23:42 2011
@@ -102,7 +102,7 @@
 	      if (errno == ENOSYS)
 		__have_dup3 = -1;
 
-	      dup2 (_IO_fileno (result), fd);
+	      __dup2 (_IO_fileno (result), fd);
 	      if ((result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0)
 		__fcntl (fd, F_SETFD, FD_CLOEXEC);
 	    }

Modified: trunk/libc/libio/freopen64.c
==============================================================================
--- trunk/libc/libio/freopen64.c (original)
+++ trunk/libc/libio/freopen64.c Mon May 23 12:23:42 2011
@@ -86,7 +86,7 @@
 	      if (errno == ENOSYS)
 		__have_dup3 = -1;
 
-	      dup2 (_IO_fileno (result), fd);
+	      __dup2 (_IO_fileno (result), fd);
 	      if ((result->_flags2 & _IO_FLAGS2_CLOEXEC) != 0)
 		__fcntl (fd, F_SETFD, FD_CLOEXEC);
 	    }

Modified: trunk/libc/locale/setlocale.c
==============================================================================
--- trunk/libc/locale/setlocale.c (original)
+++ trunk/libc/locale/setlocale.c Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1995-2000, 2002, 2003, 2004, 2006, 2008, 2010
+/* Copyright (C) 1991, 1992, 1995-2000, 2002, 2003, 2004, 2006, 2008, 2010, 2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -125,7 +125,7 @@
 			    _nl_global_locale.__names[i]);
 	last_len = strlen (name);
 	cumlen += _nl_category_name_sizes[i] + 1 + last_len + 1;
-	if (i > 0 && same && strcmp (name, newnames[0]) != 0)
+	if (same && name != newnames[0] && strcmp (name, newnames[0]) != 0)
 	  same = 0;
       }
 

Modified: trunk/libc/localedata/ChangeLog
==============================================================================
--- trunk/libc/localedata/ChangeLog (original)
+++ trunk/libc/localedata/ChangeLog Mon May 23 12:23:42 2011
@@ -1,3 +1,9 @@
+2011-05-21  Ulrich Drepper  <drepper@xxxxxxxxx>
+
+	[BZ #12788]
+	* bug-setlocale1.c: New file.
+	* Makefile: Add rules to build and run bug-setlocale1.
+
 2011-05-17  Ulrich Drepper  <drepper@xxxxxxxxx>
 
 	[BZ #11837]

Modified: trunk/libc/localedata/Makefile
==============================================================================
--- trunk/libc/localedata/Makefile (original)
+++ trunk/libc/localedata/Makefile Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-# Copyright (C) 1996-2003,2005,2007,2008,2009 Free Software Foundation, Inc.
+# Copyright (C) 1996-2003,2005,2007,2008,2009,2011 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
@@ -109,7 +109,7 @@
 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 tst-strptime
+	tst-strfmon1 tst-sscanf tst-strptime bug-setlocale1
 ifeq (yesy,$(build-shared)$(OPTION_EGLIBC_LOCALE_CODE))
 ifneq (no,$(PERL))
 tests: $(objpfx)mtrace-tst-leaks
@@ -330,5 +330,8 @@
 $(objpfx)mtrace-tst-leaks: $(objpfx)tst-leaks.out
 	$(common-objpfx)malloc/mtrace $(objpfx)tst-leaks.mtrace > $@
 
+bug-setlocale1-ENV = LOCPATH=$(common-objpfx)localedata
+bug-setlocale1-ARGS = $(common-objpfx)
+
 $(objdir)/iconvdata/gconv-modules:
 	$(MAKE) -C ../iconvdata subdir=iconvdata $@

Modified: trunk/libc/math/Makefile
==============================================================================
--- trunk/libc/math/Makefile (original)
+++ trunk/libc/math/Makefile Mon May 23 12:23:42 2011
@@ -93,7 +93,7 @@
 tests = test-matherr test-fenv basic-test \
 	test-misc test-fpucw tst-definitions test-tgmath test-tgmath-ret \
 	bug-nextafter bug-nexttoward bug-tgmath1 test-tgmath-int test-tgmath2 \
-	test-dbl-wrap
+	test-dbl-wrap test-powl
 tests-$(OPTION_EGLIBC_LIBM_BIG) += atest-exp atest-sincos atest-exp2
 # We do the `long double' tests only if this data type is available and
 # distinct from `double'.
@@ -138,6 +138,7 @@
 CFLAGS-test-tgmath.c = -fno-builtin
 CFLAGS-test-tgmath2.c = -fno-builtin
 CFLAGS-test-tgmath-ret.c = -fno-builtin
+CFLAGS-test-powl.c = -fno-builtin
 CPPFLAGS-test-ifloat.c = -U__LIBC_INTERNAL_MATH_INLINES -D__FAST_MATH__ \
 			 -DTEST_FAST_MATH -fno-builtin
 CPPFLAGS-test-idouble.c = -U__LIBC_INTERNAL_MATH_INLINES -D__FAST_MATH__ \

Modified: trunk/libc/nis/nss_nis/nis-alias.c
==============================================================================
--- trunk/libc/nis/nss_nis/nis-alias.c (original)
+++ trunk/libc/nis/nss_nis/nis-alias.c Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2002, 2003, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2002, 2003, 2006, 2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@xxxxxxxxxxxxxxxxxxx>, 1996.
 
@@ -142,10 +142,10 @@
       int yperr;
 
       if (new_start)
-        yperr = yp_first (domain, "mail.aliases", &outkey, &keylen, &result,
+	yperr = yp_first (domain, "mail.aliases", &outkey, &keylen, &result,
 			  &len);
       else
-        yperr = yp_next (domain, "mail.aliases", oldkey, oldkeylen, &outkey,
+	yperr = yp_next (domain, "mail.aliases", oldkey, oldkeylen, &outkey,
 			 &keylen, &result, &len);
 
       if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
@@ -153,20 +153,20 @@
 	  enum nss_status retval = yperr2nss (yperr);
 
 	  if (retval == NSS_STATUS_TRYAGAIN)
-            *errnop = errno;
-          return retval;
-        }
+	    *errnop = errno;
+	  return retval;
+	}
 
       if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
-        {
+	{
 	  free (result);
-          *errnop = ERANGE;
-          return NSS_STATUS_TRYAGAIN;
-        }
+	  *errnop = ERANGE;
+	  return NSS_STATUS_TRYAGAIN;
+	}
       char *p = strncpy (buffer, result, len);
       buffer[len] = '\0';
       while (isspace (*p))
-        ++p;
+	++p;
       free (result);
 
       parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer,
@@ -213,12 +213,24 @@
       return NSS_STATUS_UNAVAIL;
     }
 
-  size_t namlen = strlen (name);
-  char name2[namlen + 1];
-
   char *domain;
   if (__builtin_expect (yp_get_default_domain (&domain), 0))
     return NSS_STATUS_UNAVAIL;
+
+  size_t namlen = strlen (name);
+  char *name2;
+  int use_alloca = __libc_use_alloca (namlen + 1);
+  if (use_alloca)
+    name2 = __alloca (namlen + 1);
+  else
+    {
+      name2 = malloc (namlen + 1);
+      if (name2 == NULL)
+	{
+	  *errnop = ENOMEM;
+	  return NSS_STATUS_TRYAGAIN;
+	}
+    }
 
   /* Convert name to lowercase.  */
   size_t i;
@@ -230,6 +242,9 @@
   int len;
   int yperr = yp_match (domain, "mail.aliases", name2, namlen, &result, &len);
 
+  if (!use_alloca)
+    free (name2);
+
   if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
     {
       enum nss_status retval = yperr2nss (yperr);

Modified: trunk/libc/nscd/nscd_getserv_r.c
==============================================================================
--- trunk/libc/nscd/nscd_getserv_r.c (original)
+++ trunk/libc/nscd/nscd_getserv_r.c Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 2007, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 2007, 2009, 2011 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 2007.
 
@@ -17,6 +17,7 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <assert.h>
 #include <errno.h>
 #include <string.h>
 #include <not-cancel.h>
@@ -80,6 +81,7 @@
 {
   int gc_cycle;
   int nretries = 0;
+  size_t alloca_used = 0;
 
   /* If the mapping is available, try to search there instead of
      communicating with the nscd.  */
@@ -88,13 +90,23 @@
 			       &gc_cycle);
   size_t protolen = proto == NULL ? 0 : strlen (proto);
   size_t keylen = critlen + 1 + protolen + 1;
-  char *key = alloca (keylen);
+  int alloca_key = __libc_use_alloca (keylen);
+  char *key;
+  if (alloca_key)
+    key = alloca_account (keylen, alloca_used);
+  else
+    {
+      key = malloc (keylen);
+      if (key == NULL)
+	return -1;
+    }
   memcpy (__mempcpy (__mempcpy (key, crit, critlen),
 		     "/", 1), proto ?: "", protolen + 1);
 
  retry:;
   const char *s_name = NULL;
   const char *s_proto = NULL;
+  int alloca_aliases_len = 0;
   const uint32_t *aliases_len = NULL;
   const char *aliases_list = NULL;
   int retval = -1;
@@ -136,8 +148,22 @@
 	  if (((uintptr_t) aliases_len & (__alignof__ (*aliases_len) - 1))
 	      != 0)
 	    {
-	      uint32_t *tmp = alloca (serv_resp.s_aliases_cnt
-				      * sizeof (uint32_t));
+	      uint32_t *tmp;
+	      alloca_aliases_len
+		= __libc_use_alloca (alloca_used
+				     + (serv_resp.s_aliases_cnt
+					* sizeof (uint32_t)));
+	      if (alloca_aliases_len)
+		tmp = __alloca (serv_resp.s_aliases_cnt * sizeof (uint32_t));
+	      else
+		{
+		  tmp = malloc (serv_resp.s_aliases_cnt * sizeof (uint32_t));
+		  if (tmp == NULL)
+		    {
+		      retval = ENOMEM;
+		      goto out;
+		    }
+		}
 	      aliases_len = memcpy (tmp, aliases_len,
 				    serv_resp.s_aliases_cnt
 				    * sizeof (uint32_t));
@@ -217,8 +243,24 @@
 
 	  if (serv_resp.s_aliases_cnt > 0)
 	    {
-	      aliases_len = alloca (serv_resp.s_aliases_cnt
-				    * sizeof (uint32_t));
+	      assert (alloca_aliases_len == 0);
+	      alloca_aliases_len
+		= __libc_use_alloca (alloca_used
+				     + (serv_resp.s_aliases_cnt
+					* sizeof (uint32_t)));
+	      if (alloca_aliases_len)
+		aliases_len = alloca (serv_resp.s_aliases_cnt
+				      * sizeof (uint32_t));
+	      else
+		{
+		  aliases_len = malloc (serv_resp.s_aliases_cnt
+					* sizeof (uint32_t));
+		  if (aliases_len == NULL)
+		    {
+		      retval = ENOMEM;
+		      goto out_close;
+		    }
+		}
 	      vec[n].iov_base = (void *) aliases_len;
 	      vec[n].iov_len = serv_resp.s_aliases_cnt * sizeof (uint32_t);
 
@@ -329,5 +371,10 @@
 	goto retry;
     }
 
+  if (!alloca_aliases_len)
+    free ((void *) aliases_len);
+  if (!alloca_key)
+    free (key);
+
   return retval;
 }

Modified: trunk/libc/posix/glob.c
==============================================================================
--- trunk/libc/posix/glob.c (original)
+++ trunk/libc/posix/glob.c Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
+/* Copyright (C) 1991-2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -202,7 +202,7 @@
 
 static int glob_in_dir (const char *pattern, const char *directory,
 			int flags, int (*errfunc) (const char *, int),
-			glob_t *pglob);
+			glob_t *pglob, size_t alloca_used);
 extern int __glob_pattern_type (const char *pattern, int quote)
     attribute_hidden;
 
@@ -256,13 +256,18 @@
      glob_t *pglob;
 {
   const char *filename;
-  const char *dirname;
+  char *dirname = NULL;
   size_t dirlen;
   int status;
   size_t oldcount;
   int meta;
   int dirname_modified;
+  int malloc_dirname = 0;
   glob_t dirs;
+  int retval = 0;
+#ifdef _LIBC
+  size_t alloca_used = 0;
+#endif
 
   if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0)
     {
@@ -311,20 +316,26 @@
 	  const char *next;
 	  const char *rest;
 	  size_t rest_len;
-#ifdef __GNUC__
-	  char onealt[strlen (pattern) - 1];
-#else
-	  char *onealt = (char *) malloc (strlen (pattern) - 1);
-	  if (onealt == NULL)
-	    {
-	      if (!(flags & GLOB_APPEND))
+	  char *onealt;
+	  size_t pattern_len = strlen (pattern) - 1;
+#ifdef _LIBC
+	  int alloca_onealt = __libc_use_alloca (alloca_used + pattern_len);
+	  if (alloca_onealt)
+	    onealt = alloca_account (pattern_len, alloca_used);
+	  else
+#endif
+	    {
+	      onealt = (char *) malloc (pattern_len);
+	      if (onealt == NULL)
 		{
-		  pglob->gl_pathc = 0;
-		  pglob->gl_pathv = NULL;
+		  if (!(flags & GLOB_APPEND))
+		    {
+		      pglob->gl_pathc = 0;
+		      pglob->gl_pathv = NULL;
+		    }
+		  return GLOB_NOSPACE;
 		}
-	      return GLOB_NOSPACE;
-	    }
-#endif
+	    }
 
 	  /* We know the prefix for all sub-patterns.  */
 	  alt_start = mempcpy (onealt, pattern, begin - pattern);
@@ -335,9 +346,11 @@
 	  if (next == NULL)
 	    {
 	      /* It is an illegal expression.  */
-#ifndef __GNUC__
-	      free (onealt);
-#endif
+	    illegal_brace:
+#ifdef _LIBC
+	      if (__builtin_expect (!alloca_onealt, 0))
+#endif
+		free (onealt);
 	      return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
 	    }
 
@@ -347,13 +360,8 @@
 	    {
 	      rest = next_brace_sub (rest + 1, flags);
 	      if (rest == NULL)
-		{
-		  /* It is an illegal expression.  */
-#ifndef __GNUC__
-		  free (onealt);
-#endif
-		  return glob (pattern, flags & ~GLOB_BRACE, errfunc, pglob);
-		}
+		/* It is an illegal expression.  */
+		goto illegal_brace;
 	    }
 	  /* Please note that we now can be sure the brace expression
 	     is well-formed.  */
@@ -389,9 +397,10 @@
 	      /* If we got an error, return it.  */
 	      if (result && result != GLOB_NOMATCH)
 		{
-#ifndef __GNUC__
-		  free (onealt);
-#endif
+#ifdef _LIBC
+		  if (__builtin_expect (!alloca_onealt, 0))
+#endif
+		    free (onealt);
 		  if (!(flags & GLOB_APPEND))
 		    {
 		      globfree (pglob);
@@ -409,9 +418,10 @@
 	      assert (next != NULL);
 	    }
 
-#ifndef __GNUC__
-	  free (onealt);
-#endif
+#ifdef _LIBC
+	  if (__builtin_expect (!alloca_onealt, 0))
+#endif
+	    free (onealt);
 
 	  if (pglob->gl_pathc != firstc)
 	    /* We found some entries.  */
@@ -458,7 +468,7 @@
 	 case is nothing but a notation for a directory.  */
       if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern[0] == '~')
 	{
-	  dirname = pattern;
+	  dirname = (char *) pattern;
 	  dirlen = strlen (pattern);
 
 	  /* Set FILENAME to NULL as a special flag.  This is ugly but
@@ -476,9 +486,9 @@
 
 	  filename = pattern;
 #ifdef _AMIGA
-	  dirname = "";
+	  dirname = (char *) "";
 #else
-	  dirname = ".";
+	  dirname = (char *) ".";
 #endif
 	  dirlen = 0;
 	}
@@ -488,7 +498,7 @@
 	       && (flags & GLOB_NOESCAPE) == 0))
     {
       /* "/pattern" or "\\/pattern".  */
-      dirname = "/";
+      dirname = (char *) "/";
       dirlen = 1;
       ++filename;
     }
@@ -514,7 +524,17 @@
 	     from "d:/", since "d:" and "d:/" are not the same.*/
 	}
 #endif
-      newp = (char *) __alloca (dirlen + 1);
+#ifdef _LIBC
+      if (__libc_use_alloca (alloca_used + dirlen + 1))
+	newp = alloca_account (dirlen + 1, alloca_used);
+      else
+#endif
+	{
+	  newp = malloc (dirlen + 1);
+	  if (newp == NULL)
+	    return GLOB_NOSPACE;
+	  malloc_dirname = 1;
+	}
       *((char *) mempcpy (newp, pattern, dirlen)) = '\0';
       dirname = newp;
       ++filename;
@@ -554,7 +574,8 @@
 	      oldcount = pglob->gl_pathc + pglob->gl_offs;
 	      goto no_matches;
 	    }
-	  return val;
+	  retval = val;
+	  goto out;
 	}
     }
 
@@ -566,7 +587,8 @@
 	      && (dirname[2] == '\0' || dirname[2] == '/')))
 	{
 	  /* Look up home directory.  */
-	  const char *home_dir = getenv ("HOME");
+	  char *home_dir = getenv ("HOME");
+	  int malloc_home_dir = 0;
 # ifdef _AMIGA
 	  if (home_dir == NULL || home_dir[0] == '\0')
 	    home_dir = "SYS:";
@@ -586,7 +608,7 @@
 		/* `sysconf' does not support _SC_LOGIN_NAME_MAX.  Try
 		   a moderate value.  */
 		buflen = 20;
-	      name = (char *) __alloca (buflen);
+	      name = alloca_account (buflen, alloca_used);
 
 	      success = getlogin_r (name, buflen) == 0;
 	      if (success)
@@ -596,6 +618,7 @@
 		  long int pwbuflen = GETPW_R_SIZE_MAX ();
 		  char *pwtmpbuf;
 		  struct passwd pwbuf;
+		  int malloc_pwtmpbuf = 0;
 		  int save = errno;
 
 #     ifndef _LIBC
@@ -604,7 +627,18 @@
 		       Try a moderate value.  */
 		    pwbuflen = 1024;
 #     endif
-		  pwtmpbuf = (char *) __alloca (pwbuflen);
+		  if (__libc_use_alloca (alloca_used + pwbuflen))
+		    pwtmpbuf = alloca_account (pwbuflen, alloca_used);
+		  else
+		    {
+		      pwtmpbuf = malloc (pwbuflen);
+		      if (pwtmpbuf == NULL)
+			{
+			  retval = GLOB_NOSPACE;
+			  goto out;
+			}
+		      malloc_pwtmpbuf = 1;
+		    }
 
 		  while (getpwnam_r (name, &pwbuf, pwtmpbuf, pwbuflen, &p)
 			 != 0)
@@ -614,47 +648,116 @@
 			  p = NULL;
 			  break;
 			}
-#     ifdef _LIBC
-		      pwtmpbuf = extend_alloca (pwtmpbuf, pwbuflen,
+
+		      if (!malloc_pwtmpbuf
+			  && __libc_use_alloca (alloca_used
+						+ 2 * pwbuflen))
+			pwtmpbuf = extend_alloca_account (pwtmpbuf, pwbuflen,
+							  2 * pwbuflen,
+							  alloca_used);
+		      else
+			{
+			  char *newp = realloc (malloc_pwtmpbuf
+						? pwtmpbuf : NULL,
 						2 * pwbuflen);
-#     else
-		      pwbuflen *= 2;
-		      pwtmpbuf = (char *) __alloca (pwbuflen);
-#     endif
+			  if (newp == NULL)
+			    {
+			      if (__builtin_expect (malloc_pwtmpbuf, 0))
+				free (pwtmpbuf);
+			      retval = GLOB_NOSPACE;
+			      goto out;
+			    }
+			  pwtmpbuf = newp;
+			  pwbuflen = 2 * pwbuflen;
+			  malloc_pwtmpbuf = 1;
+			}
 		      __set_errno (save);
 		    }
 #    else
 		  p = getpwnam (name);
 #    endif
 		  if (p != NULL)
-		    home_dir = p->pw_dir;
+		    {
+		      if (!malloc_pwtmpbuf)
+			home_dir = p->pw_dir;
+		      else
+			{
+			  size_t home_dir_len = strlen (p->pw_dir) + 1;
+			  if (__libc_use_alloca (alloca_used + home_dir_len))
+			    home_dir = alloca_account (home_dir_len,
+						       alloca_used);
+			  else
+			    {
+			      home_dir = malloc (home_dir_len);
+			      if (home_dir == NULL)
+				{
+				  free (pwtmpbuf);
+				  retval = GLOB_NOSPACE;
+				  goto out;
+				}
+			      malloc_home_dir = 1;
+			    }
+			  memcpy (home_dir, p->pw_dir, home_dir_len);
+
+			  free (pwtmpbuf);
+			}
+		    }
 		}
 	    }
 #   endif /* ! _LIBC || __OPTION_EGLIBC_GETLOGIN */
 	  if (home_dir == NULL || home_dir[0] == '\0')
 	    {
 	      if (flags & GLOB_TILDE_CHECK)
-		return GLOB_NOMATCH;
+		{
+		  if (__builtin_expect (malloc_home_dir, 0))
+		    free (home_dir);
+		  retval = GLOB_NOMATCH;
+		  goto out;
+		}
 	      else
-		home_dir = "~"; /* No luck.  */
+		home_dir = (char *) "~"; /* No luck.  */
 	    }
 #  endif /* WINDOWS32 */
 # endif
 	  /* Now construct the full directory.  */
 	  if (dirname[1] == '\0')
 	    {
+	      if (__builtin_expect (malloc_dirname, 0))
+		free (dirname);
+
 	      dirname = home_dir;
 	      dirlen = strlen (dirname);
+	      malloc_dirname = malloc_home_dir;
 	    }
 	  else
 	    {
 	      char *newp;
 	      size_t home_len = strlen (home_dir);
-	      newp = (char *) __alloca (home_len + dirlen);
+	      int use_alloca = __libc_use_alloca (alloca_used
+						  + home_len + dirlen);
+	      if (use_alloca)
+		newp = alloca_account (home_len + dirlen, alloca_used);
+	      else
+		{
+		  newp = malloc (home_len + dirlen);
+		  if (newp == NULL)
+		    {
+		      if (__builtin_expect (malloc_home_dir, 0))
+			free (home_dir);
+		      retval = GLOB_NOSPACE;
+		      goto out;
+		    }
+		}
+
 	      mempcpy (mempcpy (newp, home_dir, home_len),
 		       &dirname[1], dirlen);
+
+	      if (__builtin_expect (malloc_dirname, 0))
+		free (dirname);
+
 	      dirname = newp;
 	      dirlen += home_len - 1;
+	      malloc_dirname = !use_alloca;
 	    }
 	  dirname_modified = 1;
 	}
@@ -662,7 +765,8 @@
       else
 	{
 	  char *end_name = strchr (dirname, '/');
-	  const char *user_name;
+	  char *user_name;
+	  int malloc_user_name = 0;
 	  const char *home_dir;
 	  char *unescape = NULL;
 
@@ -682,7 +786,18 @@
 	  else
 	    {
 	      char *newp;
-	      newp = (char *) __alloca (end_name - dirname);
+	      if (__libc_use_alloca (alloca_used + (end_name - dirname)))
+		newp = alloca_account (end_name - dirname, alloca_used);
+	      else
+		{
+		  newp = malloc (end_name - dirname);
+		  if (newp == NULL)
+		    {
+		      retval = GLOB_NOSPACE;
+		      goto out;
+		    }
+		  malloc_user_name = 1;
+		}
 	      if (unescape != NULL)
 		{
 		  char *p = mempcpy (newp, dirname + 1,
@@ -719,6 +834,7 @@
 #  if defined HAVE_GETPWNAM_R || defined _LIBC
 	    long int buflen = GETPW_R_SIZE_MAX ();
 	    char *pwtmpbuf;
+	    int malloc_pwtmpbuf = 0;
 	    struct passwd pwbuf;
 	    int save = errno;
 
@@ -728,7 +844,21 @@
 		 moderate value.  */
 	      buflen = 1024;
 #   endif
-	    pwtmpbuf = (char *) __alloca (buflen);
+	    if (__libc_use_alloca (alloca_used + buflen))
+	      pwtmpbuf = alloca_account (buflen, alloca_used);
+	    else
+	      {
+		pwtmpbuf = malloc (buflen);
+		if (pwtmpbuf == NULL)
+		  {
+		  nomem_getpw:
+		    if (__builtin_expect (malloc_user_name, 0))
+		      free (user_name);
+		    retval = GLOB_NOSPACE;
+		    goto out;
+		  }
+		malloc_pwtmpbuf = 1;
+	      }
 
 	    while (getpwnam_r (user_name, &pwbuf, pwtmpbuf, buflen, &p) != 0)
 	      {
@@ -737,40 +867,77 @@
 		    p = NULL;
 		    break;
 		  }
-#   ifdef _LIBC
-		pwtmpbuf = extend_alloca (pwtmpbuf, buflen, 2 * buflen);
-#   else
-		buflen *= 2;
-		pwtmpbuf = __alloca (buflen);
-#   endif
+		if (!malloc_pwtmpbuf
+		    && __libc_use_alloca (alloca_used + 2 * buflen))
+		  pwtmpbuf = extend_alloca_account (pwtmpbuf, buflen,
+						    2 * buflen, alloca_used);
+		else
+		  {
+		    char *newp = realloc (malloc_pwtmpbuf ? pwtmpbuf : NULL,
+					  2 * buflen);
+		    if (newp == NULL)
+		      {
+			if (__builtin_expect (malloc_pwtmpbuf, 0))
+			  free (pwtmpbuf);
+			goto nomem_getpw;
+		      }
+		    pwtmpbuf = newp;
+		    malloc_pwtmpbuf = 1;
+		  }
 		__set_errno (save);
 	      }
 #  else
 	    p = getpwnam (user_name);
 #  endif
+
+	    if (__builtin_expect (malloc_user_name, 0))
+	      free (user_name);
+
+	    /* If we found a home directory use this.  */
 	    if (p != NULL)
-	      home_dir = p->pw_dir;
+	      {
+		size_t home_len = strlen (p->pw_dir);
+		size_t rest_len = end_name == NULL ? 0 : strlen (end_name);
+
+		if (__builtin_expect (malloc_dirname, 0))
+		  free (dirname);
+		malloc_dirname = 0;
+
+		if (__libc_use_alloca (alloca_used + home_len + rest_len + 1))
+		  dirname = alloca_account (home_len + rest_len + 1,
+					    alloca_used);
+		else
+		  {
+		    dirname = malloc (home_len + rest_len + 1);
+		    if (dirname == NULL)
+		      {
+			if (__builtin_expect (malloc_pwtmpbuf, 0))
+			  free (pwtmpbuf);
+			retval = GLOB_NOSPACE;
+			goto out;
+		      }
+		    malloc_dirname = 1;
+		  }
+		*((char *) mempcpy (mempcpy (dirname, p->pw_dir, home_len),
+				    end_name, rest_len)) = '\0';
+
+		dirlen = home_len + rest_len;
+		dirname_modified = 1;
+
+		if (__builtin_expect (malloc_pwtmpbuf, 0))
+		  free (pwtmpbuf);
+	      }
 	    else
-	      home_dir = NULL;
+	      {
+		if (__builtin_expect (malloc_pwtmpbuf, 0))
+		  free (pwtmpbuf);
+
+		if (flags & GLOB_TILDE_CHECK)
+		  /* We have to regard it as an error if we cannot find the
+		     home directory.  */
+		  return GLOB_NOMATCH;
+	      }
 	  }
-	  /* If we found a home directory use this.  */
-	  if (home_dir != NULL)
-	    {
-	      char *newp;
-	      size_t home_len = strlen (home_dir);
-	      size_t rest_len = end_name == NULL ? 0 : strlen (end_name);
-	      newp = (char *) __alloca (home_len + rest_len + 1);
-	      *((char *) mempcpy (mempcpy (newp, home_dir, home_len),
-				  end_name, rest_len)) = '\0';
-	      dirname = newp;
-	      dirlen = home_len + rest_len;
-	      dirname_modified = 1;
-	    }
-	  else
-	    if (flags & GLOB_TILDE_CHECK)
-	      /* We have to regard it as an error if we cannot find the
-		 home directory.  */
-	      return GLOB_NOMATCH;
 	}
 # endif	/* Not Amiga && not WINDOWS32.  */
     }
@@ -904,7 +1071,7 @@
 	  status = glob_in_dir (filename, dirs.gl_pathv[i],
 				((flags | GLOB_APPEND)
 				 & ~(GLOB_NOCHECK | GLOB_NOMAGIC)),
-				errfunc, pglob);
+				errfunc, pglob, alloca_used);
 	  if (status == GLOB_NOMATCH)
 	    /* No matches in this directory.  Try the next.  */
 	    continue;
@@ -1005,7 +1172,8 @@
 	}
       if (dirname_modified)
 	flags &= ~(GLOB_NOCHECK | GLOB_NOMAGIC);
-      status = glob_in_dir (filename, dirname, flags, errfunc, pglob);
+      status = glob_in_dir (filename, dirname, flags, errfunc, pglob,
+			    alloca_used);
       if (status != 0)
 	{
 	  if (status == GLOB_NOMATCH && flags != orig_flags
@@ -1068,7 +1236,11 @@
 	     sizeof (char *), collated_compare);
     }
 
-  return 0;
+ out:
+  if (__builtin_expect (malloc_dirname, 0))
+    free (dirname);
+
+  return retval;
 }
 #if defined _LIBC && !defined glob
 libc_hidden_def (glob)
@@ -1278,7 +1450,7 @@
 static int
 glob_in_dir (const char *pattern, const char *directory, int flags,
 	     int (*errfunc) (const char *, int),
-	     glob_t *pglob)
+	     glob_t *pglob, size_t alloca_used)
 {
   size_t dirlen = strlen (directory);
   void *stream = NULL;
@@ -1293,10 +1465,11 @@
   struct globnames *names = &init_names;
   struct globnames *names_alloca = &init_names;
   size_t nfound = 0;
-  size_t allocasize = sizeof (init_names);
   size_t cur = 0;
   int meta;
   int save;
+
+  alloca_used += sizeof (init_names);
 
   init_names.next = NULL;
   init_names.count = INITIAL_COUNT;
@@ -1313,20 +1486,36 @@
     {
       /* Since we use the normal file functions we can also use stat()
 	 to verify the file is there.  */
-      struct stat st;
-      struct_stat64 st64;
+      union
+      {
+	struct stat st;
+	struct_stat64 st64;
+      } ust;
       size_t patlen = strlen (pattern);
-      char *fullname = (char *) __alloca (dirlen + 1 + patlen + 1);
+      int alloca_fullname = __libc_use_alloca (alloca_used
+					       + dirlen + 1 + patlen + 1);
+      char *fullname;
+      if (alloca_fullname)
+	fullname = alloca_account (dirlen + 1 + patlen + 1, alloca_used);
+      else
+	{
+	  fullname = malloc (dirlen + 1 + patlen + 1);
+	  if (fullname == NULL)
+	    return GLOB_NOSPACE;
+	}
 
       mempcpy (mempcpy (mempcpy (fullname, directory, dirlen),
 			"/", 1),
 	       pattern, patlen + 1);
       if ((__builtin_expect (flags & GLOB_ALTDIRFUNC, 0)
-	   ? (*pglob->gl_stat) (fullname, &st)
-	   : __stat64 (fullname, &st64)) == 0)
+	   ? (*pglob->gl_stat) (fullname, &ust.st)
+	   : __stat64 (fullname, &ust.st64)) == 0)
 	/* We found this file to be existing.  Now tell the rest
 	   of the function to copy this name into the result.  */
 	flags |= GLOB_NOCHECK;
+
+      if (__builtin_expect (!alloca_fullname, 0))
+	free (fullname);
     }
   else
     {
@@ -1414,9 +1603,9 @@
 			  size_t size = (sizeof (struct globnames)
 					 + ((count - INITIAL_COUNT)
 					    * sizeof (char *)));
-			  allocasize += size;
-			  if (__libc_use_alloca (allocasize))
-			    newnames = names_alloca = __alloca (size);
+			  if (__libc_use_alloca (alloca_used + size))
+			    newnames = names_alloca
+			      = alloca_account (size, alloca_used);
 			  else if ((newnames = malloc (size))
 				   == NULL)
 			    goto memory_error;

Modified: trunk/libc/posix/regex.h
==============================================================================
--- trunk/libc/posix/regex.h (original)
+++ trunk/libc/posix/regex.h Mon May 23 12:23:42 2011
@@ -350,9 +350,9 @@
 
 /* This data structure represents a compiled pattern.  Before calling
    the pattern compiler, the fields `buffer', `allocated', `fastmap',
-   `translate', and `no_sub' can be set.  After the pattern has been
-   compiled, the `re_nsub' field is available.  All other fields are
-   private to the regex routines.  */
+   and `translate' can be set.  After the pattern has been compiled,
+   the fields `re_nsub', `not_bol' and `not_eol' are available.  All
+   other fields are private to the regex routines.  */
 
 #ifndef RE_TRANSLATE_TYPE
 # define __RE_TRANSLATE_TYPE unsigned char *
@@ -477,7 +477,12 @@
 
 /* Compile the regular expression PATTERN, with length LENGTH
    and syntax given by the global `re_syntax_options', into the buffer
-   BUFFER.  Return NULL if successful, and an error string if not.  */
+   BUFFER.  Return NULL if successful, and an error string if not.
+
+   To free the allocated storage, you must call `regfree' on BUFFER.
+   Note that the translate table must either have been initialised by
+   `regcomp', with a malloc'ed value, or set to NULL before calling
+   `regfree'.  */
 extern const char *re_compile_pattern (const char *__pattern, size_t __length,
 				       struct re_pattern_buffer *__buffer);
 

Modified: trunk/libc/stdio-common/perror.c
==============================================================================
--- trunk/libc/stdio-common/perror.c (original)
+++ trunk/libc/stdio-common/perror.c Mon May 23 12:23:42 2011
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991-1993,1997,1998,2000-2005 Free Software Foundation, Inc.
+/* Copyright (C) 1991-1993,1997,1998,2000-2005,2011
+   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
@@ -73,6 +74,10 @@
 	 position.  Since the stderr stream wasn't used so far we just
 	 write to the descriptor.  */
       perror_internal (fp, s, errnum);
+
+      if (_IO_ferror_unlocked (fp))
+	stderr->_flags |= _IO_ERR_SEEN;
+
       /* Close the stream.  */
       fclose (fp);
     }

Modified: trunk/libc/stdio-common/vfprintf.c
==============================================================================
--- trunk/libc/stdio-common/vfprintf.c (original)
+++ trunk/libc/stdio-common/vfprintf.c Mon May 23 12:23:42 2011
@@ -53,6 +53,7 @@
       CHECK_FILE (S, -1);						      \
       if (S->_flags & _IO_NO_WRITES)					      \
 	{								      \
+	  S->_flags |= _IO_ERR_SEEN;					      \
 	  __set_errno (EBADF);						      \
 	  return -1;							      \
 	}								      \

Modified: trunk/libc/stdlib/longlong.h
==============================================================================
--- trunk/libc/stdlib/longlong.h (original)
+++ trunk/libc/stdlib/longlong.h Mon May 23 12:23:42 2011
@@ -1,6 +1,7 @@
 /* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
    Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2002, 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc.
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+   Free Software Foundation, Inc.
 
    This file is part of the GNU C Library.
 
@@ -9,6 +10,15 @@
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
 
+   In addition to the permissions in the GNU Lesser General Public
+   License, the Free Software Foundation gives you unlimited
+   permission to link the compiled version of this file into
+   combinations with other programs, and to distribute those
+   combinations without any restriction coming from the use of this
+   file.  (The Lesser General Public License restrictions do apply in
+   other respects; for example, they cover modification of the file,
+   and distribution when not linked into a combine executable.)
+
    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
@@ -16,8 +26,8 @@
 
    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.  */
+   Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+   MA 02110-1301, USA.  */
 
 /* You have to define the following before including this file:
 
@@ -43,6 +53,11 @@
 #define UWtype		USItype
 #define UHWtype		USItype
 #define UDWtype		UDItype
+#endif
+
+/* Used in glibc only.  */
+#ifndef attribute_hidden
+#define attribute_hidden
 #endif
 
 extern const UQItype __clz_tab[256] attribute_hidden;
@@ -303,6 +318,7 @@
 #endif
 
 #if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
+#if !defined (__zarch__)
 #define smul_ppmm(xh, xl, m0, m1) \
   do {									\
     union {DItype __ll;							\
@@ -324,6 +340,28 @@
 	     : "0" (__x.__ll), "r" (d));				\
     (q) = __x.__i.__l; (r) = __x.__i.__h;				\
   } while (0)
+#else
+#define smul_ppmm(xh, xl, m0, m1) \
+  do {                                                                  \
+    register SItype r0 __asm__ ("0");                                   \
+    register SItype r1 __asm__ ("1") = m0;                              \
+                                                                        \
+    __asm__ ("mr\t%%r0,%3"                                              \
+             : "=r" (r0), "=r" (r1)                                     \
+             : "r"  (r1),  "r" (m1));                                   \
+    (xh) = r1; (xl) = r0;                                               \
+  } while (0)
+#define sdiv_qrnnd(q, r, n1, n0, d) \
+  do {									\
+    register SItype r0 __asm__ ("0") = n0;                              \
+    register SItype r1 __asm__ ("1") = n1;                              \
+                                                                        \
+    __asm__ ("dr\t%%r0,%3"						\
+	     : "=r" (r0), "=r" (r1)		         		\
+	     : "r" (r0), "r" (r1), "r" (d));				\
+    (q) = r0; (r) = r1;                  				\
+  } while (0)
+#endif /* __zarch__ */
 #endif
 
 #if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
@@ -416,6 +454,55 @@
 	       "dI" ((USItype) (v)));					\
     __w; })
 #endif /* __i960__ */
+
+#if defined (__ia64) && W_TYPE_SIZE == 64
+/* This form encourages gcc (pre-release 3.4 at least) to emit predicated
+   "sub r=r,r" and "sub r=r,r,1", giving a 2 cycle latency.  The generic
+   code using "al<bl" arithmetically comes out making an actual 0 or 1 in a
+   register, which takes an extra cycle.  */
+#define sub_ddmmss(sh, sl, ah, al, bh, bl)				\
+  do {									\
+    UWtype __x;								\
+    __x = (al) - (bl);							\
+    if ((al) < (bl))							\
+      (sh) = (ah) - (bh) - 1;						\
+    else								\
+      (sh) = (ah) - (bh);						\
+    (sl) = __x;								\
+  } while (0)
+
+/* Do both product parts in assembly, since that gives better code with
+   all gcc versions.  Some callers will just use the upper part, and in
+   that situation we waste an instruction, but not any cycles.  */
+#define umul_ppmm(ph, pl, m0, m1)					\
+  __asm__ ("xma.hu %0 = %2, %3, f0\n\txma.l %1 = %2, %3, f0"		\
+	   : "=&f" (ph), "=f" (pl)					\
+	   : "f" (m0), "f" (m1))
+#define count_leading_zeros(count, x)					\
+  do {									\
+    UWtype _x = (x), _y, _a, _c;					\
+    __asm__ ("mux1 %0 = %1, @rev" : "=r" (_y) : "r" (_x));		\
+    __asm__ ("czx1.l %0 = %1" : "=r" (_a) : "r" (-_y | _y));		\
+    _c = (_a - 1) << 3;							\
+    _x >>= _c;								\
+    if (_x >= 1 << 4)							\
+      _x >>= 4, _c += 4;						\
+    if (_x >= 1 << 2)							\
+      _x >>= 2, _c += 2;						\
+    _c += _x >> 1;							\
+    (count) =  W_TYPE_SIZE - 1 - _c;					\
+  } while (0)
+/* similar to what gcc does for __builtin_ffs, but 0 based rather than 1
+   based, and we don't need a special case for x==0 here */
+#define count_trailing_zeros(count, x)					\
+  do {									\
+    UWtype __ctz_x = (x);						\
+    __asm__ ("popcnt %0 = %1"						\
+	     : "=r" (count)						\
+	     : "r" ((__ctz_x-1) & ~__ctz_x));				\
+  } while (0)
+#define UMUL_TIME 14
+#endif
 
 #if defined (__M32R__) && W_TYPE_SIZE == 32
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
@@ -631,6 +718,43 @@
 #endif /* __mc88110__ */
 #endif /* __m88000__ */
 
+#if defined (__mn10300__)
+# if defined (__AM33__)
+#  define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clz (X))
+#  define umul_ppmm(w1, w0, u, v)		\
+    asm("mulu %3,%2,%1,%0" : "=r"(w0), "=r"(w1) : "r"(u), "r"(v))
+#  define smul_ppmm(w1, w0, u, v)		\
+    asm("mul %3,%2,%1,%0" : "=r"(w0), "=r"(w1) : "r"(u), "r"(v))
+# else
+#  define umul_ppmm(w1, w0, u, v)		\
+    asm("nop; nop; mulu %3,%0" : "=d"(w0), "=z"(w1) : "%0"(u), "d"(v))
+#  define smul_ppmm(w1, w0, u, v)		\
+    asm("nop; nop; mul %3,%0" : "=d"(w0), "=z"(w1) : "%0"(u), "d"(v))
+# endif
+# define add_ssaaaa(sh, sl, ah, al, bh, bl)	\
+  do {						\
+    DWunion __s, __a, __b;			\
+    __a.s.low = (al); __a.s.high = (ah);	\
+    __b.s.low = (bl); __b.s.high = (bh);	\
+    __s.ll = __a.ll + __b.ll;			\
+    (sl) = __s.s.low; (sh) = __s.s.high;	\
+  } while (0)
+# define sub_ddmmss(sh, sl, ah, al, bh, bl)	\
+  do {						\
+    DWunion __s, __a, __b;			\
+    __a.s.low = (al); __a.s.high = (ah);	\
+    __b.s.low = (bl); __b.s.high = (bh);	\
+    __s.ll = __a.ll - __b.ll;			\
+    (sl) = __s.s.low; (sh) = __s.s.high;	\
+  } while (0)
+# define udiv_qrnnd(q, r, nh, nl, d)		\
+  asm("divu %2,%0" : "=D"(q), "=z"(r) : "D"(d), "0"(nl), "1"(nh))
+# define sdiv_qrnnd(q, r, nh, nl, d)		\
+  asm("div %2,%0" : "=D"(q), "=z"(r) : "D"(d), "0"(nl), "1"(nh))
+# define UMUL_TIME 3
+# define UDIV_TIME 38
+#endif
+
 #if defined (__mips__) && W_TYPE_SIZE == 32
 #define umul_ppmm(w1, w0, u, v)						\
   do {									\
@@ -926,8 +1050,7 @@
 #define sub_ddmmss(sh, sl, ah, al, bh, bl)				\
   __asm__ ("clrt;subc %5,%1; subc %4,%0"				\
 	   : "=r" (sh), "=r" (sl)					\
-	   : "0" (ah), "1" (al), "r" (bh), "r" (bl)			\
-	   : "t")
+	   : "0" (ah), "1" (al), "r" (bh), "r" (bl) : "t")
 
 #endif /* __sh__ */
 
@@ -1261,6 +1384,28 @@
 #define count_trailing_zeros(COUNT, X)	((COUNT) = __builtin_ctz (X))
 #endif /* __xtensa__ */
 
+#if defined xstormy16
+extern UHItype __stormy16_count_leading_zeros (UHItype);
+#define count_leading_zeros(count, x)					\
+  do									\
+    {									\
+      UHItype size;							\
+									\
+      /* We assume that W_TYPE_SIZE is a multiple of 16...  */		\
+      for ((count) = 0, size = W_TYPE_SIZE; size; size -= 16)		\
+	{								\
+	  UHItype c;							\
+									\
+	  c = __clzhi2 ((x) >> (size - 16));				\
+	  (count) += c;							\
+	  if (c != 16)							\
+	    break;							\
+	}								\
+    }									\
+  while (0)
+#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
+#endif
+
 #if defined (__z8000__) && W_TYPE_SIZE == 16
 #define add_ssaaaa(sh, sl, ah, al, bh, bl) \
   __asm__ ("add	%H1,%H5\n\tadc	%H0,%H3"				\

Modified: trunk/libc/string/_strerror.c
==============================================================================
--- trunk/libc/string/_strerror.c (original)
+++ trunk/libc/string/_strerror.c Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991,93,95,96,97,98,2000,2002,2006
+/* Copyright (C) 1991,93,95,96,97,98,2000,2002,2006,2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -18,7 +18,9 @@
    02111-1307 USA.  */
 
 #include <libintl.h>
+#include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <sys/param.h>
 #include <stdio-common/_itoa.h>
@@ -43,15 +45,21 @@
 	 `int' of 8 bytes we never need more than 20 digits.  */
       char numbuf[21];
       const char *unk = _("Unknown error ");
-      const size_t unklen = strlen (unk);
+      size_t unklen = strlen (unk);
       char *p, *q;
+      bool negative = errnum < 0;
 
       numbuf[20] = '\0';
-      p = _itoa_word (errnum, &numbuf[20], 10, 0);
+      p = _itoa_word (abs (errnum), &numbuf[20], 10, 0);
 
       /* Now construct the result while taking care for the destination
 	 buffer size.  */
       q = __mempcpy (buf, unk, MIN (unklen, buflen));
+      if (negative && unklen < buflen)
+	{
+	  *q++ = '-';
+	  ++unklen;
+	}
       if (unklen < buflen)
 	memcpy (q, p, MIN ((size_t) (&numbuf[21] - p), buflen - unklen));
 

Modified: trunk/libc/string/xpg-strerror.c
==============================================================================
--- trunk/libc/string/xpg-strerror.c (original)
+++ trunk/libc/string/xpg-strerror.c Mon May 23 12:23:42 2011
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2002, 2004, 2010
+/* Copyright (C) 1991, 1993, 1995-1998, 2000, 2002, 2004, 2010, 2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -17,36 +17,32 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <assert.h>
 #include <errno.h>
-#include <libintl.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/param.h>
-#include <stdio-common/_itoa.h>
 
-/* It is critical here that we always use the `dcgettext' function for
-   the message translation.  Since <libintl.h> only defines the macro
-   `dgettext' to use `dcgettext' for optimizing programs this is not
-   always guaranteed.  */
-#ifndef dgettext
-# include <locale.h>		/* We need LC_MESSAGES.  */
-# define dgettext(domainname, msgid) dcgettext (domainname, msgid, LC_MESSAGES)
-#endif
 
 /* Fill buf with a string describing the errno code in ERRNUM.  */
 int
 __xpg_strerror_r (int errnum, char *buf, size_t buflen)
 {
-  if (errnum < 0 || errnum >= _sys_nerr_internal
-      || _sys_errlist_internal[errnum] == NULL)
-    return EINVAL;
+  const char *estr = __strerror_r (errnum, buf, buflen);
+  size_t estrlen = strlen (estr);
 
-  const char *estr = (const char *) _(_sys_errlist_internal[errnum]);
-  size_t estrlen = strlen (estr) + 1;
+  if (estr == buf)
+    {
+      assert (errnum < 0 || errnum >= _sys_nerr_internal
+	      || _sys_errlist_internal[errnum] == NULL);
+      return EINVAL;
+    }
+  assert (errnum >= 0 && errnum < _sys_nerr_internal
+	  && _sys_errlist_internal[errnum] != NULL);
 
-  if (buflen < estrlen)
-    return ERANGE;
+  /* Terminate the string in any case.  */
+  if (buflen > 0)
+    *((char *) __mempcpy (buf, estr, MIN (buflen - 1, estrlen))) = '\0';
 
-  memcpy (buf, estr, estrlen);
-  return 0;
+  return buflen <= estrlen ? ERANGE : 0;
 }

Modified: trunk/libc/sysdeps/posix/getaddrinfo.c
==============================================================================
--- trunk/libc/sysdeps/posix/getaddrinfo.c (original)
+++ trunk/libc/sysdeps/posix/getaddrinfo.c Mon May 23 12:23:42 2011
@@ -278,6 +278,7 @@
   bool got_ipv6 = false;
   const char *canon = NULL;
   const char *orig_name = name;
+  size_t alloca_used = 0;
 
   if (req->ai_protocol || req->ai_socktype)
     {
@@ -310,7 +311,7 @@
 	  if (tp->name[0])
 	    {
 	      st = (struct gaih_servtuple *)
-		__alloca (sizeof (struct gaih_servtuple));
+		alloca_account (sizeof (struct gaih_servtuple), alloca_used);
 
 	      if ((rc = gaih_inet_serv (service->name, tp, req, st)))
 		return rc;
@@ -334,7 +335,8 @@
 		    continue;
 
 		  newp = (struct gaih_servtuple *)
-		    __alloca (sizeof (struct gaih_servtuple));
+		    alloca_account (sizeof (struct gaih_servtuple),
+				    alloca_used);
 
 		  if ((rc = gaih_inet_serv (service->name, tp, req, newp)))
 		    {
@@ -362,7 +364,7 @@
 
       if (req->ai_socktype || req->ai_protocol)
 	{
-	  st = __alloca (sizeof (struct gaih_servtuple));
+	  st = alloca_account (sizeof (struct gaih_servtuple), alloca_used);
 	  st->next = NULL;
 	  st->socktype = tp->socktype;
 	  st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
@@ -379,7 +381,8 @@
 	      {
 		struct gaih_servtuple *newp;
 
-		newp = __alloca (sizeof (struct gaih_servtuple));
+		newp = alloca_account (sizeof (struct gaih_servtuple),
+				       alloca_used);
 		newp->next = NULL;
 		newp->socktype = tp->socktype;
 		newp->protocol = tp->protocol;
@@ -391,10 +394,17 @@
 	}
     }
 
+  bool malloc_name = false;
+  bool malloc_addrmem = false;
+  struct gaih_addrtuple *addrmem = NULL;
+  bool malloc_canonbuf = false;
+  char *canonbuf = NULL;
+  bool malloc_tmpbuf = false;
+  char *tmpbuf = NULL;
+  int result = 0;
   if (name != NULL)
     {
-      at = __alloca (sizeof (struct gaih_addrtuple));
-
+      at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used);
       at->family = AF_UNSPEC;
       at->scopeid = 0;
       at->next = NULL;
@@ -412,6 +422,7 @@
 	  rc = __idna_to_ascii_lz (name, &p, idn_flags);
 	  if (rc != IDNA_SUCCESS)
 	    {
+	      /* No need to jump to free_and_return here.  */
 	      if (rc == IDNA_MALLOC_ERROR)
 		return -EAI_MEMORY;
 	      if (rc == IDNA_DLOPEN_ERROR)
@@ -421,10 +432,7 @@
 	  /* In case the output string is the same as the input string
 	     no new string has been allocated.  */
 	  if (p != name)
-	    {
-	      name = strdupa (p);
-	      free (p);
-	    }
+	    malloc_name = true;
 	}
 #endif
 
@@ -441,23 +449,59 @@
 	      at->family = AF_INET6;
 	    }
 	  else
-	    return -EAI_ADDRFAMILY;
+	    {
+	      result = -EAI_ADDRFAMILY;
+	      goto free_and_return;
+	    }
 
 	  if (req->ai_flags & AI_CANONNAME)
 	    canon = name;
 	}
       else if (at->family == AF_UNSPEC)
 	{
-	  char *namebuf = (char *) name;
 	  char *scope_delim = strchr (name, SCOPE_DELIMITER);
-
-	  if (__builtin_expect (scope_delim != NULL, 0))
-	    {
-	      namebuf = alloca (scope_delim - name + 1);
-	      *((char *) __mempcpy (namebuf, name, scope_delim - name)) = '\0';
-	    }
-
-	  if (inet_pton (AF_INET6, namebuf, at->addr) > 0)
+	  int e;
+
+	  {
+	    bool malloc_namebuf = false;
+	    char *namebuf = (char *) name;
+
+	    if (__builtin_expect (scope_delim != NULL, 0))
+	      {
+		if (malloc_name)
+		  *scope_delim = '\0';
+		else
+		  {
+		    if (__libc_use_alloca (alloca_used
+					   + scope_delim - name + 1))
+		      {
+			namebuf = alloca_account (scope_delim - name + 1,
+						  alloca_used);
+			*((char *) __mempcpy (namebuf, name,
+					      scope_delim - name)) = '\0';
+		      }
+		    else
+		      {
+			namebuf = strndup (name, scope_delim - name);
+			if (namebuf == NULL)
+			  {
+			    assert (!malloc_name);
+			    return -EAI_MEMORY;
+			  }
+			malloc_namebuf = true;
+		      }
+		  }
+	      }
+
+	    e = inet_pton (AF_INET6, namebuf, at->addr);
+
+	    if (malloc_namebuf)
+	      free (namebuf);
+	    else if (scope_delim != NULL && malloc_name)
+	      /* Undo what we did above.  */
+	      *scope_delim = SCOPE_DELIMITER;
+	  }
+	  if (e > 0)
 	    {
 	      if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
 		at->family = AF_INET6;
@@ -468,7 +512,10 @@
 		  at->family = AF_INET;
 		}
 	      else
-		return -EAI_ADDRFAMILY;
+		{
+		  result = -EAI_ADDRFAMILY;
+		  goto free_and_return;
+		}
 
 	      if (scope_delim != NULL)
 		{
@@ -490,7 +537,10 @@
 		      at->scopeid = (uint32_t) strtoul (scope_delim + 1, &end,
 							10);
 		      if (*end != '\0')
-			return GAIH_OKIFUNSPEC | -EAI_NONAME;
+			{
+			  result = GAIH_OKIFUNSPEC | -EAI_NONAME;
+			  goto free_and_return;
+			}
 		    }
 		}
 
@@ -517,7 +567,8 @@
 	    {
 	      int family = req->ai_family;
 	      size_t tmpbuflen = 512;
-	      char *tmpbuf = alloca (tmpbuflen);
+	      assert (tmpbuf == NULL);
+	      tmpbuf = alloca_account (tmpbuflen, alloca_used);
 	      int rc;
 	      struct hostent th;
 	      struct hostent *h;
@@ -529,50 +580,95 @@
 					   tmpbuflen, &h, &herrno);
 		  if (rc != ERANGE || herrno != NETDB_INTERNAL)
 		    break;
-		  tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen);
+
+		  if (!malloc_tmpbuf
+		      && __libc_use_alloca (alloca_used + 2 * tmpbuflen))
+		    tmpbuf = extend_alloca_account (tmpbuf, tmpbuflen,
+						    2 * tmpbuflen,
+						    alloca_used);
+		  else
+		    {
+		      char *newp = realloc (malloc_tmpbuf ? tmpbuf : NULL,
+					    2 * tmpbuflen);
+		      if (newp == NULL)
+			{
+			  result = -EAI_MEMORY;
+			  goto free_and_return;
+			}
+		      tmpbuf = newp;
+		      malloc_tmpbuf = true;
+		      tmpbuflen = 2 * tmpbuflen;
+		    }
 		}
 
 	      if (rc == 0)
 		{
 		  if (h != NULL)
-		    /* We found data, now convert it into the list.  */
-		    for (int i = 0; h->h_addr_list[i]; ++i)
-		      {
-			if (*pat == NULL)
-			  {
-			    *pat = __alloca (sizeof (struct gaih_addrtuple));
-			    (*pat)->scopeid = 0;
-			  }
-			(*pat)->next = NULL;
-			(*pat)->family = req->ai_family;
-			if (family == req->ai_family)
-			  memcpy ((*pat)->addr, h->h_addr_list[i],
-				  h->h_length);
-			else
-			  {
-			    uint32_t *addr = (uint32_t *) (*pat)->addr;
-			    addr[3] = *(uint32_t *) h->h_addr_list[i];
-			    addr[2] = htonl (0xffff);
-			    addr[1] = 0;
-			    addr[0] = 0;
-			  }
-			pat = &((*pat)->next);
-		      }
+		    {
+		      int i;
+		      /* We found data, count the number of addresses.  */
+		      for (i = 0; h->h_addr_list[i]; ++i)
+			;
+		      if (i > 0 && *pat != NULL)
+			--i;
+
+		      if (__libc_use_alloca (alloca_used
+					     + i * sizeof (struct gaih_addrtuple)))
+			addrmem = alloca_account (i * sizeof (struct gaih_addrtuple),
+						  alloca_used);
+		      else
+			{
+			  addrmem = malloc (i
+					    * sizeof (struct gaih_addrtuple));
+			  if (addrmem == NULL)
+			    {
+			      result = -EAI_MEMORY;
+			      goto free_and_return;
+			    }
+			  malloc_addrmem = true;
+			}
+
+		      /* Now convert it into the list.  */
+		      struct gaih_addrtuple *addrfree = addrmem;
+		      for (i = 0; h->h_addr_list[i]; ++i)
+			{
+			  if (*pat == NULL)
+			    {
+			      *pat = addrfree++;
+			      (*pat)->scopeid = 0;
+			    }
+			  (*pat)->next = NULL;
+			  (*pat)->family = req->ai_family;
+			  if (family == req->ai_family)
+			    memcpy ((*pat)->addr, h->h_addr_list[i],
+				    h->h_length);
+			  else
+			    {
+			      uint32_t *addr = (uint32_t *) (*pat)->addr;
+			      addr[3] = *(uint32_t *) h->h_addr_list[i];
+			      addr[2] = htonl (0xffff);
+			      addr[1] = 0;
+			      addr[0] = 0;
+			    }
+			  pat = &((*pat)->next);
+			}
+		    }
 		}
 	      else
 		{
 		  if (herrno == NETDB_INTERNAL)
 		    {
 		      __set_h_errno (herrno);
-		      return -EAI_SYSTEM;
+		      result = -EAI_SYSTEM;
 		    }
-		  if (herrno == TRY_AGAIN)
-		    {
-		      return -EAI_AGAIN;
-		    }
-		  /* We made requests but they turned out no data.
-		     The name is known, though.  */
-		  return GAIH_OKIFUNSPEC | -EAI_NODATA;
+		  else if (herrno == TRY_AGAIN)
+		    result = -EAI_AGAIN;
+		  else
+		    /* We made requests but they turned out no data.
+		       The name is known, though.  */
+		    result = GAIH_OKIFUNSPEC | -EAI_NODATA;
+
+		  goto free_and_return;
 		}
 
 	      goto process_list;
@@ -596,21 +692,56 @@
 		  bool added_canon = (req->ai_flags & AI_CANONNAME) == 0;
 		  char *addrs = air->addrs;
 
+		  if (__libc_use_alloca (alloca_used
+					 + air->naddrs * sizeof (struct gaih_addrtuple)))
+		    addrmem = alloca_account (air->naddrs
+					      * sizeof (struct gaih_addrtuple),
+					      alloca_used);
+		  else
+		    {
+		      addrmem = malloc (air->naddrs
+					* sizeof (struct gaih_addrtuple));
+		      if (addrmem == NULL)
+			{
+			  result = -EAI_MEMORY;
+			  goto free_and_return;
+			}
+		      malloc_addrmem = true;
+		    }
+
+		  struct gaih_addrtuple *addrfree = addrmem;
 		  for (int i = 0; i < air->naddrs; ++i)
 		    {
 		      socklen_t size = (air->family[i] == AF_INET
 					? INADDRSZ : IN6ADDRSZ);
 		      if (*pat == NULL)
 			{
-			  *pat = __alloca (sizeof (struct gaih_addrtuple));
+			  *pat = addrfree++;
 			  (*pat)->scopeid = 0;
 			}
 		      uint32_t *pataddr = (*pat)->addr;
 		      (*pat)->next = NULL;
 		      if (added_canon || air->canon == NULL)
 			(*pat)->name = NULL;
-		      else
-			canon = (*pat)->name = strdupa (air->canon);
+		      else if (canonbuf == NULL)
+			{
+			  size_t canonlen = strlen (air->canon) + 1;
+			  if ((req->ai_flags & AI_CANONIDN) != 0
+			      && __libc_use_alloca (alloca_used + canonlen))
+			    canonbuf = alloca_account (canonlen, alloca_used);
+			  else
+			    {
+			      canonbuf = malloc (canonlen);
+			      if (canonbuf == NULL)
+				{
+				  result = -EAI_MEMORY;
+				  goto free_and_return;
+				}
+			      malloc_canonbuf = true;
+			    }
+			  canon = (*pat)->name = memcpy (canonbuf, air->canon,
+							 canonlen);
+			}
 
 		      if (air->family[i] == AF_INET
 			  && req->ai_family == AF_INET6
@@ -640,20 +771,26 @@
 		  free (air);
 
 		  if (at->family == AF_UNSPEC)
-		    return GAIH_OKIFUNSPEC | -EAI_NONAME;
+		    {
+		      result = GAIH_OKIFUNSPEC | -EAI_NONAME;
+		      goto free_and_return;
+		    }
 
 		  goto process_list;
 		}
 	      else if (err == 0)
 		/* The database contains a negative entry.  */
-		return 0;
+		goto free_and_return;
 	      else if (__nss_not_use_nscd_hosts == 0)
 		{
 		  if (herrno == NETDB_INTERNAL && errno == ENOMEM)
-		    return -EAI_MEMORY;
-		  if (herrno == TRY_AGAIN)
-		    return -EAI_AGAIN;
-		  return -EAI_SYSTEM;
+		    result = -EAI_MEMORY;
+		  else if (herrno == TRY_AGAIN)
+		    result = -EAI_AGAIN;
+		  else
+		    result = -EAI_SYSTEM;
+
+		  goto free_and_return;
 		}
 	    }
 #endif
@@ -682,7 +819,19 @@
 	  _res.options &= ~RES_USE_INET6;
 
 	  size_t tmpbuflen = 1024;
-	  char *tmpbuf = alloca (tmpbuflen);
+	  malloc_tmpbuf = !__libc_use_alloca (alloca_used + tmpbuflen);
+	  assert (tmpbuf == NULL);
+	  if (malloc_tmpbuf)
+	    tmpbuf = alloca_account (tmpbuflen, alloca_used);
+	  else
+	    {
+	      tmpbuf = malloc (tmpbuflen);
+	      if (tmpbuf == NULL)
+		{
+		  result = -EAI_MEMORY;
+		  goto free_and_return;
+		}
+	    }
 
 	  while (!no_more)
 	    {
@@ -711,8 +860,25 @@
 			    no_data = herrno == NO_DATA;
 			  break;
 			}
-		      tmpbuf = extend_alloca (tmpbuf,
-					      tmpbuflen, 2 * tmpbuflen);
+
+		      if (!malloc_tmpbuf
+			  && __libc_use_alloca (alloca_used + 2 * tmpbuflen))
+			tmpbuf = extend_alloca_account (tmpbuf, tmpbuflen,
+							2 * tmpbuflen,
+							alloca_used);
+		      else
+			{
+			  char *newp = realloc (malloc_tmpbuf ? tmpbuf : NULL,
+						2 * tmpbuflen);
+			  if (newp == NULL)
+			    {
+			      result = -EAI_MEMORY;
+			      goto free_and_return;
+			    }
+			  tmpbuf = newp;
+			  malloc_tmpbuf = true;
+			  tmpbuflen = 2 * tmpbuflen;
+			}
 		    }
 
 		  no_inet6_data = no_data;
@@ -787,18 +953,40 @@
 			      if (cfct != NULL)
 				{
 				  const size_t max_fqdn_len = 256;
-				  char *buf = alloca (max_fqdn_len);
+				  if ((req->ai_flags & AI_CANONIDN) != 0
+				      && __libc_use_alloca (alloca_used
+							    + max_fqdn_len))
+				    canonbuf = alloca_account (max_fqdn_len,
+							       alloca_used);
+				  else
+				    {
+				      canonbuf = malloc (max_fqdn_len);
+				      if (canonbuf == NULL)
+					{
+					  result = -EAI_MEMORY;
+					  goto free_and_return;
+					}
+				      malloc_canonbuf = true;
+				    }
 				  char *s;
 
 				  if (DL_CALL_FCT (cfct, (at->name ?: name,
-							  buf, max_fqdn_len,
+							  canonbuf,
+							  max_fqdn_len,
 							  &s, &rc, &herrno))
 				      == NSS_STATUS_SUCCESS)
 				    canon = s;
 				  else
-				    /* Set to name now to avoid using
-				       gethostbyaddr.  */
-				    canon = name;
+				    {
+				      /* Set to name now to avoid using
+					 gethostbyaddr.  */
+				      if (malloc_canonbuf)
+					{
+					  free (canonbuf);
+					  malloc_canonbuf = false;
+					}
+				      canon = name;
+				    }
 				}
 			    }
 			  status = NSS_STATUS_SUCCESS;
@@ -833,22 +1021,27 @@
 	    {
 	      /* If both requests timed out report this.  */
 	      if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN)
-		return -EAI_AGAIN;
-
-	      /* We made requests but they turned out no data.  The name
-		 is known, though.  */
-	      return GAIH_OKIFUNSPEC | -EAI_NODATA;
+		result = -EAI_AGAIN;
+	      else
+		/* We made requests but they turned out no data.  The name
+		   is known, though.  */
+		result = GAIH_OKIFUNSPEC | -EAI_NODATA;
+
+	      goto free_and_return;
 	    }
 	}
 
     process_list:
       if (at->family == AF_UNSPEC)
-	return GAIH_OKIFUNSPEC | -EAI_NONAME;
+	{
+	  result = GAIH_OKIFUNSPEC | -EAI_NONAME;
+	  goto free_and_return;
+	}
     }
   else
     {
       struct gaih_addrtuple *atr;
-      atr = at = __alloca (sizeof (struct gaih_addrtuple));
+      atr = at = alloca_account (sizeof (struct gaih_addrtuple), alloca_used);
       memset (at, '\0', sizeof (struct gaih_addrtuple));
 
       if (req->ai_family == AF_UNSPEC)
@@ -887,30 +1080,56 @@
 	/* Only the first entry gets the canonical name.  */
 	if (at2 == at && (req->ai_flags & AI_CANONNAME) != 0)
 	  {
+	    char *tmpbuf2 = NULL;
+	    bool malloc_tmpbuf2 = false;
+
 	    if (canon == NULL)
 	      {
 		struct hostent *h = NULL;
 		int herrno;
 		struct hostent th;
-		size_t tmpbuflen = 512;
-		char *tmpbuf = NULL;
+		size_t tmpbuf2len = 512;
 
 		do
 		  {
-		    tmpbuf = extend_alloca (tmpbuf, tmpbuflen, tmpbuflen * 2);
+		    if (__libc_use_alloca (alloca_used + 2 * tmpbuf2len))
+		      tmpbuf2 = extend_alloca_account (tmpbuf2, tmpbuf2len,
+						       tmpbuf2len * 2,
+						       alloca_used);
+		    else
+		      {
+			char *newp = realloc (malloc_tmpbuf2 ? tmpbuf2 : NULL,
+					      2 * tmpbuf2len);
+			if (newp == NULL)
+			  {
+			    if (malloc_tmpbuf2)
+			      free (tmpbuf2);
+			    result = -EAI_MEMORY;
+			    goto free_and_return;
+			  }
+
+			tmpbuf2 = newp;
+			tmpbuf2len = 2 * tmpbuf2len;
+			malloc_tmpbuf2 = true;
+		      }
+
 		    rc = __gethostbyaddr_r (at2->addr,
 					    ((at2->family == AF_INET6)
 					     ? sizeof (struct in6_addr)
 					     : sizeof (struct in_addr)),
-					    at2->family, &th, tmpbuf,
-					    tmpbuflen, &h, &herrno);
+					    at2->family, &th, tmpbuf2,
+					    tmpbuf2len, &h, &herrno);
 		  }
 		while (rc == ERANGE && herrno == NETDB_INTERNAL);
 
 		if (rc != 0 && herrno == NETDB_INTERNAL)
 		  {
+		    if (malloc_tmpbuf2)
+		      free (tmpbuf2);
+
 		    __set_h_errno (herrno);
-		    return -EAI_SYSTEM;
+		    result = -EAI_SYSTEM;
+		    goto free_and_return;
 		  }
 
 		if (h != NULL)
@@ -937,11 +1156,16 @@
 		int rc = __idna_to_unicode_lzlz (canon, &out, idn_flags);
 		if (rc != IDNA_SUCCESS)
 		  {
+		    if (malloc_tmpbuf2)
+		      free (tmpbuf2);
+
 		    if (rc == IDNA_MALLOC_ERROR)
-		      return -EAI_MEMORY;
-		    if (rc == IDNA_DLOPEN_ERROR)
-		      return -EAI_SYSTEM;
-		    return -EAI_IDN_ENCODE;
+		      result = -EAI_MEMORY;
+		    else if (rc == IDNA_DLOPEN_ERROR)
+		      result = -EAI_SYSTEM;
+		    else
+		      result = -EAI_IDN_ENCODE;
+		    goto free_and_return;
 		  }
 		/* In case the output string is the same as the input
 		   string no new string has been allocated and we
@@ -956,10 +1180,25 @@
 #ifdef HAVE_LIBIDN
 	      make_copy:
 #endif
-		canon = strdup (canon);
-		if (canon == NULL)
-		  return -EAI_MEMORY;
+		if (malloc_canonbuf)
+		  /* We already allocated the string using malloc.  */
+		  malloc_canonbuf = false;
+		else
+		  {
+		    canon = strdup (canon);
+		    if (canon == NULL)
+		      {
+			if (malloc_tmpbuf2)
+			  free (tmpbuf2);
+
+			result = -EAI_MEMORY;
+			goto free_and_return;
+		      }
+		  }
 	      }
+
+	    if (malloc_tmpbuf2)
+	      free (tmpbuf2);
 	  }
 
 	family = at2->family;
@@ -985,7 +1224,8 @@
 	    if (ai == NULL)
 	      {
 		free ((char *) canon);
-		return -EAI_MEMORY;
+		result = -EAI_MEMORY;
+		goto free_and_return;
 	      }
 
 	    ai->ai_flags = req->ai_flags;
@@ -1038,7 +1278,18 @@
 	at2 = at2->next;
       }
   }
-  return 0;
+
+ free_and_return:
+  if (malloc_name)
+    free ((char *) name);
+  if (malloc_addrmem)
+    free (addrmem);
+  if (malloc_canonbuf)
+    free (canonbuf);
+  if (malloc_tmpbuf)
+    free (tmpbuf);
+
+  return result;
 }
 
 

Modified: trunk/libc/sysdeps/powerpc/powerpc64/Makefile
==============================================================================
--- trunk/libc/sysdeps/powerpc/powerpc64/Makefile (original)
+++ trunk/libc/sysdeps/powerpc/powerpc64/Makefile Mon May 23 12:23:42 2011
@@ -12,7 +12,10 @@
 
 # These flags prevent FPU or Altivec registers from being used,
 # for code called in contexts that is not allowed to touch those registers.
-# Stupid GCC requires us to pass all these ridiculous switches.
+# Stupid GCC requires us to pass all these ridiculous switches.  We need to
+# pass the -mno-* switches as well to prevent the compiler from attempting
+# to emit altivec or vsx instructions, especially when the registers aren't
+# available.
 no-special-regs := $(sort $(foreach n,40 41 50 51 60 61 62 63 \
 				      $(foreach m,2 3 4 5 6 7 8 9, \
 						  3$m 4$m 5$m),\
@@ -20,7 +23,7 @@
 		   $(sort $(foreach n,$(foreach m,0 1 2 3 4 5 6 7 8 9,\
 						$m 1$m 2$m) 30 31,\
 				    -ffixed-v$n)) \
-		   -ffixed-vrsave -ffixed-vscr
+		   -ffixed-vrsave -ffixed-vscr -mno-altivec -mno-vsx
 
 ifeq ($(subdir),csu)
 sysdep_routines += hp-timing

Modified: trunk/libc/sysdeps/unix/sysv/linux/bits/time.h
==============================================================================
--- trunk/libc/sysdeps/unix/sysv/linux/bits/time.h (original)
+++ trunk/libc/sysdeps/unix/sysv/linux/bits/time.h Mon May 23 12:23:42 2011
@@ -73,6 +73,10 @@
 #   define CLOCK_MONOTONIC_COARSE	6
 /* Monotonic system-wide clock that includes time spent in suspension.  */
 #   define CLOCK_BOOTTIME		7
+/* Like CLOCK_REALTIME but also wakes suspended system.  */
+#   define CLOCK_REALTIME_ALARM		8
+/* Like CLOCK_BOOTTIME but also wakes suspended system.  */
+#   define CLOCK_BOOTTIME_ALARM		9
 
 /* Flag to indicate time is absolute.  */
 #   define TIMER_ABSTIME		1

Modified: trunk/libc/sysdeps/unix/sysv/linux/ia64/sysconf.c
==============================================================================
--- trunk/libc/sysdeps/unix/sysv/linux/ia64/sysconf.c (original)
+++ trunk/libc/sysdeps/unix/sysv/linux/ia64/sysconf.c Mon May 23 12:23:42 2011
@@ -24,7 +24,7 @@
 
 
 #include "has_cpuclock.c"
-#define HAS_CPUCLOCK() (has_cpuclock () ? _POSIX_VERSION : -1)
+#define HAS_CPUCLOCK(name) (has_cpuclock () ? _POSIX_VERSION : -1)
 
 
 /* Now the generic Linux version.  */

Modified: trunk/libc/sysdeps/unix/sysv/linux/sysconf.c
==============================================================================
--- trunk/libc/sysdeps/unix/sysv/linux/sysconf.c (original)
+++ trunk/libc/sysdeps/unix/sysv/linux/sysconf.c Mon May 23 12:23:42 2011
@@ -37,7 +37,7 @@
 
 #ifndef HAS_CPUCLOCK
 static long int
-has_cpuclock (void)
+has_cpuclock (int name)
 {
 # if defined __NR_clock_getres || HP_TIMING_AVAIL
   /* If we have HP_TIMING, we will fall back on that if the system
@@ -59,7 +59,7 @@
   return -1;
 # endif
 }
-# define HAS_CPUCLOCK() has_cpuclock ()
+# define HAS_CPUCLOCK(name) has_cpuclock (name)
 #endif
 
 
@@ -86,7 +86,7 @@
 
     case _SC_CPUTIME:
     case _SC_THREAD_CPUTIME:
-      return HAS_CPUCLOCK ();
+      return HAS_CPUCLOCK (name);
 
     case _SC_ARG_MAX:
 #if __LINUX_KERNEL_VERSION < 0x020617

Modified: trunk/libc/sysdeps/x86_64/fpu/e_powl.S
==============================================================================
--- trunk/libc/sysdeps/x86_64/fpu/e_powl.S (original)
+++ trunk/libc/sysdeps/x86_64/fpu/e_powl.S Mon May 23 12:23:42 2011
@@ -1,5 +1,5 @@
 /* ix87 specific implementation of pow function.
-   Copyright (C) 1996, 1997, 1998, 1999, 2001, 2004, 2007
+   Copyright (C) 1996, 1997, 1998, 1999, 2001, 2004, 2007, 2011
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@xxxxxxxxxx>, 1996.
@@ -154,7 +154,7 @@
 	fucompp			// 1.0 : x : y
 	fnstsw
 	fxch			// x : 1.0 : y
-	test	$4500,%eax
+	test	$0x4500,%eax
 	jz	7f
 	fsub	%st(1)		// x-1 : 1.0 : y
 	fyl2xp1			// log2(x) : y