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.
This commit is contained in:
Ulrich Drepper
2002-07-15 23:37:22 +00:00
parent c3da4f0cba
commit 706d1dee46
9 changed files with 163 additions and 11 deletions
+1 -1
View File
@@ -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.
+52
View File
@@ -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;
}
+28 -2
View File
@@ -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;