This is the mail archive of the
glibc-cvs@sourceware.org
mailing list for the glibc project.
GNU C Library master sources branch, master, updated. glibc-2.13-162-g20030ae
- From: drepper at sourceware dot org
- To: glibc-cvs at sourceware dot org
- Date: 14 May 2011 01:10:46 -0000
- Subject: GNU C Library master sources branch, master, updated. glibc-2.13-162-g20030ae
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 20030ae6d7e7187d7caf1b23c4aa5471fcf56d47 (commit)
via fcabc0f8b185f9e0a9289720be5ede6c39b3bf21 (commit)
from 320a5dc07b907b1e640fd11ce49a04aa2b367711 (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=20030ae6d7e7187d7caf1b23c4aa5471fcf56d47
commit 20030ae6d7e7187d7caf1b23c4aa5471fcf56d47
Author: Ulrich Drepper <drepper@gmail.com>
Date: Fri May 13 21:10:29 2011 -0400
Fix error messages in test.
diff --git a/ChangeLog b/ChangeLog
index 3ca2d58..839ad68 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2011-05-13 Ulrich Drepper <drepper@gmail.com>
+ * libio/tst_putwc.c: Fix error messages.
+
[BZ #12724]
* libio/fileops.c (_IO_new_file_close_it): Always flush when
currently writing and seek to current position when not.
diff --git a/libio/tst_putwc.c b/libio/tst_putwc.c
index 1fd21e2..c6e7a9d 100644
--- a/libio/tst_putwc.c
+++ b/libio/tst_putwc.c
@@ -1,5 +1,5 @@
/* Simple test of putwc in the C locale.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2011 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
@@ -74,13 +74,16 @@ do_test (void)
/* Now close the file, open it again, and read again. */
if (fclose (fp) != 0)
{
- printf ("failure during fclose(): %m");
+ printf ("failure during fclose: %m\n");
res = 1;
}
fp = fopen (outname, "r");
if (fp == NULL)
- error (EXIT_FAILURE, errno, "cannot reopen file");
+ {
+ printf ("cannot reopen file: %m\n");
+ return 1;
+ }
/* We can remove the file now. */
remove (outname);
@@ -104,7 +107,7 @@ do_test (void)
if (fclose (fp) != 0)
{
- puts ("failure during fclose()");
+ printf ("failure during fclose: %m\n");
res = 1;
}
http://sources.redhat.com/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=fcabc0f8b185f9e0a9289720be5ede6c39b3bf21
commit fcabc0f8b185f9e0a9289720be5ede6c39b3bf21
Author: Ulrich Drepper <drepper@gmail.com>
Date: Fri May 13 21:08:45 2011 -0400
Fix file descriptor position after fclose
fclose should leave the file descriptor position after the last read
or written byte.
diff --git a/ChangeLog b/ChangeLog
index 824ec0e..3ca2d58 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-05-13 Ulrich Drepper <drepper@gmail.com>
+
+ [BZ #12724]
+ * libio/fileops.c (_IO_new_file_close_it): Always flush when
+ currently writing and seek to current position when not.
+ * libio/Makefile (tests): Add bug-fclose1.
+ * libio/bug-fclose1.c: New file.
+
2011-05-12 Ulrich Drepper <drepper@gmail.com>
[BZ #12511]
diff --git a/NEWS b/NEWS
index b8afa6e..2fc193c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU C Library NEWS -- history of user-visible changes. 2011-5-11
+GNU C Library NEWS -- history of user-visible changes. 2011-5-13
Copyright (C) 1992-2009, 2010, 2011 Free Software Foundation, Inc.
See the end for copying conditions.
@@ -13,7 +13,8 @@ Version 2.14
12052, 12158, 12178, 12200, 12346, 12393, 12420, 12445, 12449, 12454,
12460, 12469, 12489, 12509, 12510, 12511, 12518, 12527, 12541, 12545,
12551, 12583, 12587, 12597, 12611, 12625, 12631, 12650, 12653, 12655,
- 12660, 12681, 12685, 12711, 12713, 12714, 12717, 12723, 12734, 12738
+ 12660, 12681, 12685, 12711, 12713, 12714, 12717, 12723, 12724, 12734,
+ 12738
* The RPC implementation in libc is obsoleted. Old programs keep working
but new programs cannot be linked with the routines in libc anymore.
diff --git a/libio/Makefile b/libio/Makefile
index 83b9458..ec30904 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1995-2004,2006,2007,2008,2009 Free Software Foundation, Inc.
+# Copyright (C) 1995-2004,2006-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
@@ -58,7 +58,7 @@ 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
+ tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos bug-fclose1
test-srcs = test-freopen
all: # Make this the default target; it will be defined in Rules.
diff --git a/libio/bug-fclose1.c b/libio/bug-fclose1.c
new file mode 100644
index 0000000..f1e09f5
--- /dev/null
+++ b/libio/bug-fclose1.c
@@ -0,0 +1,132 @@
+// BZ #12724
+
+static void do_prepare (void);
+#define PREPARE(argc, argv) do_prepare ()
+static int do_test (void);
+#define TEST_FUNCTION do_test()
+#include "../test-skeleton.c"
+
+
+static int fd;
+
+
+static void
+do_prepare (void)
+{
+ fd = create_temp_file ("bug-fclose1.", NULL);
+ if (fd == -1)
+ {
+ printf ("cannot create temporary file: %m\n");
+ exit (1);
+ }
+}
+
+
+static int
+do_test (void)
+{
+ static const char pattern[] = "hello world";
+
+ /* Prepare a seekable file. */
+ if (write (fd, pattern, sizeof pattern) != sizeof pattern)
+ {
+ printf ("cannot write pattern: %m\n");
+ return 1;
+ }
+ if (lseek (fd, 1, SEEK_SET) != 1)
+ {
+ printf ("cannot seek after write: %m\n");
+ return 1;
+ }
+
+ /* Create an output stream visiting the file; when it is closed, all
+ other file descriptors visiting the file must see the new file
+ position. */
+ int fd2 = dup (fd);
+ if (fd2 < 0)
+ {
+ printf ("cannot duplicate descriptor for writing: %m\n");
+ return 1;
+ }
+ FILE *f = fdopen (fd2, "w");
+ if (f == NULL)
+ {
+ printf ("first fdopen failed: %m\n");
+ return 1;
+ }
+ if (fputc (pattern[1], f) != pattern[1])
+ {
+ printf ("fputc failed: %m\n");
+ return 1;
+ }
+ if (fclose (f) != 0)
+ {
+ printf ("first fclose failed: %m\n");
+ return 1;
+ }
+ errno = 0;
+ if (lseek (fd2, 0, SEEK_CUR) != -1)
+ {
+ printf ("lseek after fclose after write did not fail\n");
+ return 1;
+ }
+ if (errno != EBADF)
+ {
+ printf ("lseek after fclose after write did not fail with EBADF: %m\n");
+ return 1;
+ }
+ off_t o = lseek (fd, 0, SEEK_CUR);
+ if (o != 2)
+ {
+ printf ("\
+lseek on original descriptor after first fclose returned %ld, expected 2\n",
+ (long int) o);
+ return 1;
+ }
+
+ /* Likewise for an input stream. */
+ fd2 = dup (fd);
+ if (fd2 < 0)
+ {
+ printf ("cannot duplicate descriptor for reading: %m\n");
+ return 1;
+ }
+ f = fdopen (fd2, "r");
+ if (f == NULL)
+ {
+ printf ("second fdopen failed: %m\n");
+ return 1;
+ }
+ char c = fgetc (f);
+ if (c != pattern[2])
+ {
+ printf ("getc returned %c, expected %c\n", c, pattern[2]);
+ return 1;
+ }
+ if (fclose (f) != 0)
+ {
+ printf ("second fclose failed: %m\n");
+ return 1;
+ }
+ errno = 0;
+ if (lseek (fd2, 0, SEEK_CUR) != -1)
+ {
+ printf ("lseek after fclose after read did not fail\n");
+ return 1;
+ }
+ if (errno != EBADF)
+ {
+ printf ("lseek after fclose after read did not fail with EBADF: %m\n");
+ return 1;
+ }
+ o = lseek (fd, 0, SEEK_CUR);
+ if (o != 3)
+ {
+ printf ("\
+lseek on original descriptor after second fclose returned %ld, expected 3\n",
+ (long int) o);
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/libio/fileops.c b/libio/fileops.c
index ea730ac..678e32a 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -160,19 +160,25 @@ int
_IO_new_file_close_it (fp)
_IO_FILE *fp;
{
- int write_status, close_status;
if (!_IO_file_is_open (fp))
return EOF;
- if ((fp->_flags & _IO_NO_WRITES) == 0
- && (fp->_flags & _IO_CURRENTLY_PUTTING) != 0)
+ int write_status;
+ if (_IO_in_put_mode (fp))
write_status = _IO_do_flush (fp);
- else
- write_status = 0;
+ else if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
+ && !_IO_in_backup (fp))
+ {
+ off64_t o = _IO_SEEKOFF (fp, 0, _IO_seek_cur, 0);
+ if (o == WEOF)
+ write_status = EOF;
+ else
+ write_status = _IO_SYSSEEK (fp, o, SEEK_SET) < 0 ? EOF : 0;
+ }
INTUSE(_IO_unsave_markers) (fp);
- close_status = _IO_SYSCLOSE (fp);
+ int close_status = _IO_SYSCLOSE (fp);
/* Free buffer. */
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
-----------------------------------------------------------------------
Summary of changes:
ChangeLog | 10 ++++
NEWS | 5 +-
libio/Makefile | 4 +-
libio/bug-fclose1.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++
libio/fileops.c | 18 +++++--
libio/tst_putwc.c | 11 +++--
6 files changed, 166 insertions(+), 14 deletions(-)
create mode 100644 libio/bug-fclose1.c
hooks/post-receive
--
GNU C Library master sources