1
This patch reverts the following commit, which causes problem with ruby.
3
2011-05-13 Ulrich Drepper <drepper@gmail.com>
6
* libio/fileops.c (_IO_new_file_close_it): Always flush when
7
currently writing and seek to current position when not.
8
* libio/Makefile (tests): Add bug-fclose1.
9
* libio/bug-fclose1.c: New file.
13
libio/bug-fclose1.c | 132 ----------------------------------------------------
14
libio/fileops.c | 14 +----
15
3 files changed, 4 insertions(+), 144 deletions(-)
20
tst-mmap2-eofsync tst-mmap-offend bug-fopena+ \
21
bug-ungetc2 bug-ungetc3 bug-ungetc4 \
22
tst-memstream1 tst-memstream2 \
23
- bug-memstream1 tst-popen1 bug-fclose1
24
+ bug-memstream1 tst-popen1
25
tests-$(OPTION_EGLIBC_LOCALE_CODE) \
26
+= tst-swscanf tst-fgetws tst-fopenloc tst-setvbuf1 \
27
tst-ungetwc1 tst-ungetwc2 bug-ftell bug-ungetwc2 \
28
--- a/libio/bug-fclose1.c
33
-static void do_prepare (void);
34
-#define PREPARE(argc, argv) do_prepare ()
35
-static int do_test (void);
36
-#define TEST_FUNCTION do_test()
37
-#include "../test-skeleton.c"
46
- fd = create_temp_file ("bug-fclose1.", NULL);
49
- printf ("cannot create temporary file: %m\n");
58
- static const char pattern[] = "hello world";
60
- /* Prepare a seekable file. */
61
- if (write (fd, pattern, sizeof pattern) != sizeof pattern)
63
- printf ("cannot write pattern: %m\n");
66
- if (lseek (fd, 1, SEEK_SET) != 1)
68
- printf ("cannot seek after write: %m\n");
72
- /* Create an output stream visiting the file; when it is closed, all
73
- other file descriptors visiting the file must see the new file
78
- printf ("cannot duplicate descriptor for writing: %m\n");
81
- FILE *f = fdopen (fd2, "w");
84
- printf ("first fdopen failed: %m\n");
87
- if (fputc (pattern[1], f) != pattern[1])
89
- printf ("fputc failed: %m\n");
92
- if (fclose (f) != 0)
94
- printf ("first fclose failed: %m\n");
98
- if (lseek (fd2, 0, SEEK_CUR) != -1)
100
- printf ("lseek after fclose after write did not fail\n");
103
- if (errno != EBADF)
105
- printf ("lseek after fclose after write did not fail with EBADF: %m\n");
108
- off_t o = lseek (fd, 0, SEEK_CUR);
112
-lseek on original descriptor after first fclose returned %ld, expected 2\n",
117
- /* Likewise for an input stream. */
121
- printf ("cannot duplicate descriptor for reading: %m\n");
124
- f = fdopen (fd2, "r");
127
- printf ("second fdopen failed: %m\n");
130
- char c = fgetc (f);
131
- if (c != pattern[2])
133
- printf ("getc returned %c, expected %c\n", c, pattern[2]);
136
- if (fclose (f) != 0)
138
- printf ("second fclose failed: %m\n");
142
- if (lseek (fd2, 0, SEEK_CUR) != -1)
144
- printf ("lseek after fclose after read did not fail\n");
147
- if (errno != EBADF)
149
- printf ("lseek after fclose after read did not fail with EBADF: %m\n");
152
- o = lseek (fd, 0, SEEK_CUR);
156
-lseek on original descriptor after second fclose returned %ld, expected 3\n",
163
--- a/libio/fileops.c
164
+++ b/libio/fileops.c
165
@@ -156,21 +156,13 @@
166
_IO_new_file_close_it (fp)
170
if (!_IO_file_is_open (fp))
174
- if (_IO_in_put_mode (fp))
175
+ if ((fp->_flags & _IO_NO_WRITES) == 0
176
+ && (fp->_flags & _IO_CURRENTLY_PUTTING) != 0)
177
write_status = _IO_do_flush (fp);
178
- else if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL
179
- && !_IO_in_backup (fp))
181
- off64_t o = _IO_SEEKOFF (fp, 0, _IO_seek_cur, 0);
183
- write_status = EOF;
185
- write_status = _IO_SYSSEEK (fp, o, SEEK_SET) < 0 ? EOF : 0;