This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


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

GNU C Library master sources branch master updated. glibc-2.16-ports-merge-775-gde2fd46


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  de2fd463b1c0310d75084b6d774fb974075a4ad9 (commit)
      from  c515fb5148f1d81d5f7736825e14c7502c15432a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=de2fd463b1c0310d75084b6d774fb974075a4ad9

commit de2fd463b1c0310d75084b6d774fb974075a4ad9
Author: Siddhesh Poyarekar <siddhesh@redhat.com>
Date:   Wed Nov 28 00:59:27 2012 +0530

    Make fwrite return 0 on EOF

diff --git a/ChangeLog b/ChangeLog
index dfe6671..1a2e4da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-11-27  Siddhesh Poyarekar  <siddhesh@redhat.com>
+
+	[BZ #11741]
+	* libio/Makefile (tests): Add test case tst-fwrite-error.
+	* libio/iofwrite.c (_IO_fwrite): Return 0 on EOF.
+	* libio/iofwrite_u.c (fwrite_unlocked): Likewise.
+	* libio/tst-fwrite-error.c: New test case.
+
 2012-11-26  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* elf/dl-load.c (_dl_map_object_from_fd): Cast to uintptr_t
diff --git a/libio/Makefile b/libio/Makefile
index 9ccd6a0..83d90d0 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -59,7 +59,8 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc   \
 	tst-memstream1 tst-memstream2 \
 	tst-wmemstream1 tst-wmemstream2 \
 	bug-memstream1 bug-wmemstream1 \
-	tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos bug-fclose1 tst-fseek
+	tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos bug-fclose1 tst-fseek \
+	tst-fwrite-error
 ifeq (yes,$(build-shared))
 # Add test-fopenloc only if shared library is enabled since it depends on
 # shared localedata objects.
diff --git a/libio/iofwrite.c b/libio/iofwrite.c
index d4610f7..2fff72b 100644
--- a/libio/iofwrite.c
+++ b/libio/iofwrite.c
@@ -42,12 +42,12 @@ _IO_fwrite (buf, size, count, fp)
   if (_IO_vtable_offset (fp) != 0 || _IO_fwide (fp, -1) == -1)
     written = _IO_sputn (fp, (const char *) buf, request);
   _IO_release_lock (fp);
-  /* We have written all of the input in case the return value indicates
-     this or EOF is returned.  The latter is a special case where we
-     simply did not manage to flush the buffer.  But the data is in the
-     buffer and therefore written as far as fwrite is concerned.  */
-  if (written == request || written == EOF)
+  /* We are guaranteed to have written all of the input, none of it, or
+     some of it.  */
+  if (written == request)
     return count;
+  else if (written == EOF)
+    return 0;
   else
     return written / size;
 }
diff --git a/libio/iofwrite_u.c b/libio/iofwrite_u.c
index a1077ee..245a93e 100644
--- a/libio/iofwrite_u.c
+++ b/libio/iofwrite_u.c
@@ -44,12 +44,12 @@ fwrite_unlocked (buf, size, count, fp)
   if (_IO_fwide (fp, -1) == -1)
     {
       written = _IO_sputn (fp, (const char *) buf, request);
-      /* We have written all of the input in case the return value indicates
-	 this or EOF is returned.  The latter is a special case where we
-	 simply did not manage to flush the buffer.  But the data is in the
-	 buffer and therefore written as far as fwrite is concerned.  */
-      if (written == request || written == EOF)
+      /* We are guaranteed to have written all of the input, none of it, or
+	 some of it.  */
+      if (written == request)
 	return count;
+      else if (written == EOF)
+	return 0;
     }
 
   return written / size;
diff --git a/libio/tst-fwrite-error.c b/libio/tst-fwrite-error.c
new file mode 100644
index 0000000..3c0cf49
--- /dev/null
+++ b/libio/tst-fwrite-error.c
@@ -0,0 +1,66 @@
+/* Test of fwrite() function, adapted from gnulib-tests in grep.
+   Copyright (C) 2011-2012 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+
+static int
+do_test (void)
+{
+  char tmpl[] = "/tmp/tst-fwrite-error.XXXXXX";
+  int fd = mkstemp (tmpl);
+  if (fd == -1)
+    {
+      printf ("mkstemp failed with errno %d\n", errno);
+      return 1;
+    }
+  FILE *fp = fdopen (fd, "w");
+  if (fp == NULL)
+    {
+      printf ("fdopen failed with errno %d\n", errno);
+      return 1;
+    }
+
+  char buf[5] = "world";
+  setvbuf (fp, NULL, _IONBF, 0);
+  close (fd);
+  unlink (tmpl);
+  errno = 0;
+
+  int ret = fwrite (buf, 1, sizeof (buf), fp);
+  if (ret != 0)
+    {
+      printf ("fwrite returned %d\n", ret);
+      return 1;
+    }
+  if (errno != EBADF)
+    {
+      printf ("Errno is not EBADF: %d\n", errno);
+      return 1;
+    }
+  if (ferror (fp) == 0)
+    {
+      printf ("ferror not set\n");
+      return 1;
+    }
+
+  return 0;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                |    8 +++++
 libio/Makefile           |    3 +-
 libio/iofwrite.c         |   10 +++---
 libio/iofwrite_u.c       |   10 +++---
 libio/tst-fwrite-error.c |   66 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 86 insertions(+), 11 deletions(-)
 create mode 100644 libio/tst-fwrite-error.c


hooks/post-receive
-- 
GNU C Library master sources


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