ce426f
diff --git glibc-2.17-c758a686/libio/fileops.c glibc-2.17-c758a686/libio/fileops.c
ce426f
index 61b61b3..5f3dae7 100644
ce426f
--- glibc-2.17-c758a686/libio/fileops.c
ce426f
+++ glibc-2.17-c758a686/libio/fileops.c
ce426f
@@ -1245,13 +1245,12 @@ _IO_new_file_write (f, data, n)
ce426f
      _IO_ssize_t n;
ce426f
 {
ce426f
   _IO_ssize_t to_do = n;
ce426f
-  _IO_ssize_t count = 0;
ce426f
   while (to_do > 0)
ce426f
     {
ce426f
-      count = (__builtin_expect (f->_flags2
ce426f
-				 & _IO_FLAGS2_NOTCANCEL, 0)
ce426f
-	       ? write_not_cancel (f->_fileno, data, to_do)
ce426f
-	       : write (f->_fileno, data, to_do));
ce426f
+      _IO_ssize_t count = (__builtin_expect (f->_flags2
ce426f
+					     & _IO_FLAGS2_NOTCANCEL, 0)
ce426f
+			   ? write_not_cancel (f->_fileno, data, to_do)
ce426f
+			   : write (f->_fileno, data, to_do));
ce426f
       if (count < 0)
ce426f
 	{
ce426f
 	  f->_flags |= _IO_ERR_SEEN;
ce426f
@@ -1263,7 +1262,7 @@ _IO_new_file_write (f, data, n)
ce426f
   n -= to_do;
ce426f
   if (f->_offset >= 0)
ce426f
     f->_offset += n;
ce426f
-  return count < 0 ? count : n;
ce426f
+  return n;
ce426f
 }
ce426f
ce426f
 _IO_size_t
ce426f
@@ -1323,13 +1322,11 @@ _IO_new_file_xsputn (f, data, n)
ce426f
       _IO_size_t block_size, do_write;
ce426f
       /* Next flush the (full) buffer. */
ce426f
       if (_IO_OVERFLOW (f, EOF) == EOF)
ce426f
-	/* If nothing else has to be written or nothing has been written, we
ce426f
-	   must not signal the caller that the call was even partially
ce426f
-	   successful.  */
ce426f
-	return (to_do == 0 || to_do == n) ? EOF : n - to_do;
ce426f
+	/* If nothing else has to be written we must not signal the
ce426f
+	   caller that everything has been written.  */
ce426f
+	return to_do == 0 ? EOF : n - to_do;
ce426f
ce426f
-      /* Try to maintain alignment: write a whole number of blocks.
ce426f
-	 dont_write is what gets left over. */
ce426f
+      /* Try to maintain alignment: write a whole number of blocks.  */
ce426f
       block_size = f->_IO_buf_end - f->_IO_buf_base;
ce426f
       do_write = to_do - (block_size >= 128 ? to_do % block_size : 0);
ce426f
ce426f
diff --git glibc-2.17-c758a686/libio/iofwrite.c glibc-2.17-c758a686/libio/iofwrite.c
ce426f
index 81596a6..66542ea 100644
ce426f
--- glibc-2.17-c758a686/libio/iofwrite.c
ce426f
+++ glibc-2.17-c758a686/libio/iofwrite.c
ce426f
@@ -42,12 +42,12 @@ _IO_fwrite (buf, size, count, fp)
ce426f
   if (_IO_vtable_offset (fp) != 0 || _IO_fwide (fp, -1) == -1)
ce426f
     written = _IO_sputn (fp, (const char *) buf, request);
ce426f
   _IO_release_lock (fp);
ce426f
-  /* We are guaranteed to have written all of the input, none of it, or
ce426f
-     some of it.  */
ce426f
-  if (written == request)
ce426f
+  /* We have written all of the input in case the return value indicates
ce426f
+     this or EOF is returned.  The latter is a special case where we
ce426f
+     simply did not manage to flush the buffer.  But the data is in the
ce426f
+     buffer and therefore written as far as fwrite is concerned.  */
ce426f
+  if (written == request || written == EOF)
ce426f
     return count;
ce426f
-  else if (written == EOF)
ce426f
-    return 0;
ce426f
   else
ce426f
     return written / size;
ce426f
 }
ce426f
diff --git glibc-2.17-c758a686/libio/iofwrite_u.c glibc-2.17-c758a686/libio/iofwrite_u.c
ce426f
index 4a9d6ca..18dc6d0 100644
ce426f
--- glibc-2.17-c758a686/libio/iofwrite_u.c
ce426f
+++ glibc-2.17-c758a686/libio/iofwrite_u.c
ce426f
@@ -44,12 +44,12 @@ fwrite_unlocked (buf, size, count, fp)
ce426f
   if (_IO_fwide (fp, -1) == -1)
ce426f
     {
ce426f
       written = _IO_sputn (fp, (const char *) buf, request);
ce426f
-      /* We are guaranteed to have written all of the input, none of it, or
ce426f
-	 some of it.  */
ce426f
-      if (written == request)
ce426f
+      /* We have written all of the input in case the return value indicates
ce426f
+	 this or EOF is returned.  The latter is a special case where we
ce426f
+	 simply did not manage to flush the buffer.  But the data is in the
ce426f
+	 buffer and therefore written as far as fwrite is concerned.  */
ce426f
+      if (written == request || written == EOF)
ce426f
 	return count;
ce426f
-      else if (written == EOF)
ce426f
-	return 0;
ce426f
     }
ce426f
ce426f
   return written / size;
ce426f
diff --git glibc-2.17-c758a686/libio/iopadn.c glibc-2.17-c758a686/libio/iopadn.c
ce426f
index cc93c0f..5ebbcf4 100644
ce426f
--- glibc-2.17-c758a686/libio/iopadn.c
ce426f
+++ glibc-2.17-c758a686/libio/iopadn.c
ce426f
@@ -59,7 +59,7 @@ _IO_padn (fp, pad, count)
ce426f
       w = _IO_sputn (fp, padptr, PADSIZE);
ce426f
       written += w;
ce426f
       if (w != PADSIZE)
ce426f
-	return w == EOF ? w : written;
ce426f
+	return written;
ce426f
     }
ce426f
ce426f
   if (i > 0)
ce426f
diff --git glibc-2.17-c758a686/libio/iowpadn.c glibc-2.17-c758a686/libio/iowpadn.c
ce426f
index d94db71..5600f37 100644
ce426f
--- glibc-2.17-c758a686/libio/iowpadn.c
ce426f
+++ glibc-2.17-c758a686/libio/iowpadn.c
ce426f
@@ -65,7 +65,7 @@ _IO_wpadn (fp, pad, count)
ce426f
       w = _IO_sputn (fp, (char *) padptr, PADSIZE);
ce426f
       written += w;
ce426f
       if (w != PADSIZE)
ce426f
-	return w == EOF ? w : written;
ce426f
+	return written;
ce426f
     }
ce426f
ce426f
   if (i > 0)
ce426f
diff --git glibc-2.17-c758a686/stdio-common/vfprintf.c glibc-2.17-c758a686/stdio-common/vfprintf.c
ce426f
index c8bcf5a..61d9dc2 100644
ce426f
--- glibc-2.17-c758a686/stdio-common/vfprintf.c
ce426f
+++ glibc-2.17-c758a686/stdio-common/vfprintf.c
ce426f
@@ -90,13 +90,13 @@
ce426f
   do {									      \
ce426f
     if (width > 0)							      \
ce426f
       {									      \
ce426f
-	unsigned int d = _IO_padn (s, (Padchar), width);		      \
ce426f
-	if (__builtin_expect (d == EOF, 0))				      \
ce426f
+	_IO_ssize_t written = _IO_padn (s, (Padchar), width);		      \
ce426f
+	if (__glibc_unlikely (written != width))			      \
ce426f
 	  {								      \
ce426f
 	    done = -1;							      \
ce426f
 	    goto all_done;						      \
ce426f
 	  }								      \
ce426f
-	done_add (d);							      \
ce426f
+	done_add (written);						      \
ce426f
       }									      \
ce426f
   } while (0)
ce426f
 # define PUTC(C, F)	_IO_putc_unlocked (C, F)
ce426f
@@ -119,13 +119,13 @@
ce426f
   do {									      \
ce426f
     if (width > 0)							      \
ce426f
       {									      \
ce426f
-	unsigned int d = _IO_wpadn (s, (Padchar), width);		      \
ce426f
-	if (__builtin_expect (d == EOF, 0))				      \
ce426f
+	_IO_ssize_t written = _IO_wpadn (s, (Padchar), width);		      \
ce426f
+	if (__glibc_unlikely (written != width))			      \
ce426f
 	  {								      \
ce426f
 	    done = -1;							      \
ce426f
 	    goto all_done;						      \
ce426f
 	  }								      \
ce426f
-	done_add (d);							      \
ce426f
+	done_add (written);						      \
ce426f
       }									      \
ce426f
   } while (0)
ce426f
 # define PUTC(C, F)	_IO_putwc_unlocked (C, F)
ce426f