1 diff -pruN glibc-2.12-2-gc4ccff1/libio/Makefile glibc-2.12-2-gc4ccff1.fseek/libio/Makefile
2 --- glibc-2.12-2-gc4ccff1/libio/Makefile 2010-05-04 16:57:23.000000000 +0530
3 +++ glibc-2.12-2-gc4ccff1.fseek/libio/Makefile 2012-09-05 17:28:08.699360413 +0530
4 @@ -58,7 +58,7 @@ tests = tst_swprintf tst_wprintf tst_sws
5 tst-memstream1 tst-memstream2 \
6 tst-wmemstream1 tst-wmemstream2 \
7 bug-memstream1 bug-wmemstream1 \
8 - tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos
9 + tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos tst-fseek
10 test-srcs = test-freopen
12 all: # Make this the default target; it will be defined in Rules.
13 diff -pruN glibc-2.12-2-gc4ccff1/libio/tst-fseek.c glibc-2.12-2-gc4ccff1.fseek/libio/tst-fseek.c
14 --- glibc-2.12-2-gc4ccff1/libio/tst-fseek.c 1970-01-01 05:30:00.000000000 +0530
15 +++ glibc-2.12-2-gc4ccff1.fseek/libio/tst-fseek.c 2012-09-05 17:27:33.606359692 +0530
17 +/* Verify that fseek/ftell combination works for wide chars.
19 + Copyright (C) 2012 Free Software Foundation, Inc.
20 + This file is part of the GNU C Library.
22 + The GNU C Library is free software; you can redistribute it and/or
23 + modify it under the terms of the GNU Lesser General Public
24 + License as published by the Free Software Foundation; either
25 + version 2.1 of the License, or (at your option) any later version.
27 + The GNU C Library is distributed in the hope that it will be useful,
28 + but WITHOUT ANY WARRANTY; without even the implied warranty of
29 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 + Lesser General Public License for more details.
32 + You should have received a copy of the GNU Lesser General Public
33 + License along with the GNU C Library; if not, see
34 + <http://www.gnu.org/licenses/>. */
44 +/* Defined in test-skeleton.c. */
45 +static int create_temp_file (const char *base, char **filename);
49 +do_seek_end (FILE *fp)
55 + printf ("do_seek_end: fopen: %s\n", strerror (errno));
59 + if (fputws (L"abc\n", fp) == -1)
61 + printf ("do_seek_end: fputws: %s\n", strerror (errno));
68 + if (fseek (fp, 0, SEEK_END) == -1)
70 + printf ("do_seek_end: fseek: %s\n", strerror (errno));
74 + if (save != ftell (fp))
76 + printf ("save = %ld, ftell = %ld\n", save, ftell (fp));
84 +do_seek_set (FILE *fp)
88 + if (fputws (L"abc\n", fp) == -1)
90 + printf ("seek_set: fputws: %s\n", strerror (errno));
96 + if (fputws (L"xyz\n", fp) == -1)
98 + printf ("seek_set: fputws: %s\n", strerror (errno));
102 + if (fseek (fp, save, SEEK_SET) == -1)
104 + printf ("seek_set: fseek: %s\n", strerror (errno));
108 + if (save != ftell (fp))
110 + printf ("save = %ld, ftell = %ld\n", save, ftell (fp));
120 + if (setlocale (LC_ALL, "en_US.utf8") == NULL)
122 + printf ("Cannot set en_US.utf8 locale.\n");
128 + int fd = create_temp_file ("tst-fseek.out", &filename);
133 + FILE *fp = fdopen (fd, "w+");
136 + printf ("seek_set: fopen: %s\n", strerror (errno));
141 + if (do_seek_set (fp))
143 + printf ("SEEK_SET test failed\n");
147 + /* Reopen the file. */
149 + fp = fopen (filename, "w+");
152 + printf ("seek_end: fopen: %s\n", strerror (errno));
156 + if (do_seek_end (fp))
158 + printf ("SEEK_END test failed\n");
168 +#define TEST_FUNCTION do_test ()
169 +#include "../test-skeleton.c"
170 diff -pruN glibc-2.12-2-gc4ccff1/libio/wfileops.c glibc-2.12-2-gc4ccff1.fseek/libio/wfileops.c
171 --- glibc-2.12-2-gc4ccff1/libio/wfileops.c 2010-05-04 16:57:23.000000000 +0530
172 +++ glibc-2.12-2-gc4ccff1.fseek/libio/wfileops.c 2012-09-05 17:27:33.608359685 +0530
173 @@ -547,6 +547,55 @@ _IO_wfile_sync (fp)
175 INTDEF(_IO_wfile_sync)
177 +/* Adjust the internal buffer pointers to reflect the state in the external
178 + buffer. The content between fp->_IO_read_base and fp->_IO_read_ptr is
179 + assumed to be converted and available in the range
180 + fp->_wide_data->_IO_read_base and fp->_wide_data->_IO_read_end. */
182 +adjust_wide_data (_IO_FILE *fp, bool do_convert)
184 + struct _IO_codecvt *cv = fp->_codecvt;
186 + int clen = (*cv->__codecvt_do_encoding) (cv);
188 + /* Take the easy way out for constant length encodings if we don't need to
190 + if (!do_convert && clen > 0)
192 + fp->_wide_data->_IO_read_end += ((fp->_IO_read_ptr - fp->_IO_read_base)
197 + enum __codecvt_result status;
198 + const char *read_stop = (const char *) fp->_IO_read_base;
202 + fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
203 + status = (*cv->__codecvt_do_in) (cv, &fp->_wide_data->_IO_state,
204 + fp->_IO_read_base, fp->_IO_read_ptr,
206 + fp->_wide_data->_IO_read_base,
207 + fp->_wide_data->_IO_buf_end,
208 + &fp->_wide_data->_IO_read_end);
210 + /* Should we return EILSEQ? */
211 + if (__builtin_expect (status == __codecvt_error, 0))
213 + fp->_flags |= _IO_ERR_SEEN;
217 + while (__builtin_expect (status == __codecvt_partial, 0));
220 + /* Now seek to the end of the read buffer. */
221 + fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end;
227 _IO_wfile_seekoff (fp, offset, dir, mode)
229 @@ -695,6 +744,10 @@ _IO_wfile_seekoff (fp, offset, dir, mode
230 fp->_wide_data->_IO_buf_base);
231 _IO_wsetp (fp, fp->_wide_data->_IO_buf_base,
232 fp->_wide_data->_IO_buf_base);
234 + if (adjust_wide_data (fp, false))
237 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);
240 @@ -735,6 +788,10 @@ _IO_wfile_seekoff (fp, offset, dir, mode
241 _IO_wsetg (fp, fp->_wide_data->_IO_buf_base,
242 fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base);
243 _IO_wsetp (fp, fp->_wide_data->_IO_buf_base, fp->_wide_data->_IO_buf_base);
245 + if (adjust_wide_data (fp, true))
248 fp->_offset = result + count;
249 _IO_mask_flags (fp, 0, _IO_EOF_SEEN);