diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-07-15 23:37:22 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-07-15 23:37:22 +0000 |
commit | 706d1dee4692cc5419275fcddc4518933ff2a39e (patch) | |
tree | c795b0e8236092f2345ac7803181e41c13c5427c /libio | |
parent | c3da4f0cba685e6918d2babb286bd731ae7eab71 (diff) | |
download | glibc-706d1dee4692cc5419275fcddc4518933ff2a39e.tar.gz glibc-706d1dee4692cc5419275fcddc4518933ff2a39e.tar.xz glibc-706d1dee4692cc5419275fcddc4518933ff2a39e.zip |
Update.
2002-07-15 Ulrich Drepper <drepper@redhat.com> * libio/wfileops.c (_IO_wfile_seekoff): Reposition wide pointers and adjust state for seek position. [PR libc/4070] * libio/Makefile (tests): Add bug-rewind. * libio/bug-rewind.c: New file.
Diffstat (limited to 'libio')
-rw-r--r-- | libio/Makefile | 2 | ||||
-rw-r--r-- | libio/bug-rewind.c | 52 | ||||
-rw-r--r-- | libio/wfileops.c | 30 |
3 files changed, 81 insertions, 3 deletions
diff --git a/libio/Makefile b/libio/Makefile index f4c5095e5f..cb390a53d6 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -50,7 +50,7 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-fopenloc \ tst-fgetws tst-ungetwc1 tst-ungetwc2 tst-swscanf tst-sscanf \ tst-mmap-setvbuf bug-ungetwc1 bug-ungetwc2 tst-atime tst-eof \ - tst-freopen + tst-freopen bug-rewind test-srcs = test-freopen all: # Make this the default target; it will be defined in Rules. diff --git a/libio/bug-rewind.c b/libio/bug-rewind.c new file mode 100644 index 0000000000..2a30d28e25 --- /dev/null +++ b/libio/bug-rewind.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <wchar.h> + +#define PASSED 0 +#define FAILED 3 + + +int +main (void) +{ + FILE *fptr; + char arg1; + char arg2; + int ret, ret1, ret2, result, num; + + ret1 = 0; + ret2 = 0; + + if ((fptr = fopen ("./wrewind.dat", "w+")) == NULL) + { + printf ("Unable to open file.\n"); + return 1; + } + + if ((ret = fwprintf (fptr, L"cderf")) <= 0) + { + printf ("Unable to write to file with fwprintf().\n"); + fclose (fptr); + return 2; + } + + rewind (fptr); + ret1 = fwscanf (fptr, L"%c%c", &arg1, &arg2); + + rewind (fptr); + ret2 = fwscanf (fptr, L"%c%n%c", &arg1, &num, &arg2); + + if (arg2 != 'd') + { + result = FAILED; + printf ("rewind after first fwscanf failed\n"); + } + else + { + printf ("Passed\n"); + result = PASSED; + } + + + fclose (fptr); + return result; +} diff --git a/libio/wfileops.c b/libio/wfileops.c index b633daf51c..04a8f27834 100644 --- a/libio/wfileops.c +++ b/libio/wfileops.c @@ -635,6 +635,10 @@ _IO_wfile_seekoff (fp, offset, dir, mode) #endif if (rel_offset <= fp->_IO_read_end - fp->_IO_read_base) { + enum __codecvt_result status; + struct _IO_codecvt *cd = fp->_codecvt; + const char *read_ptr_copy; + fp->_IO_read_ptr = fp->_IO_read_base + rel_offset; _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base); @@ -643,11 +647,33 @@ _IO_wfile_seekoff (fp, offset, dir, mode) pointer is somewhere in the current external buffer this does not mean we can convert this whole buffer at once fitting in the internal buffer. */ + fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state; + read_ptr_copy = fp->_IO_read_base; + fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_base; do { - + wchar_t buffer[1024]; + wchar_t *ignore; + status = (*cd->__codecvt_do_in) (cd, + &fp->_wide_data->_IO_state, + read_ptr_copy, + fp->_IO_read_ptr, + &read_ptr_copy, + buffer, + buffer + + (sizeof (buffer) + / sizeof (buffer[0])), + &ignore); + if (status != __codecvt_ok && status != __codecvt_partial) + { + fp->_flags |= _IO_ERR_SEEN; + goto dumb; + } } - while (0); + while (read_ptr_copy != fp->_IO_read_ptr); + + fp->_wide_data->_IO_read_ptr = fp->_wide_data->_IO_read_end + = fp->_wide_data->_IO_read_base; _IO_mask_flags (fp, 0, _IO_EOF_SEEN); goto resync; |