mirror of
https://sourceware.org/git/glibc.git
synced 2025-01-03 08:11:08 +00:00
update.
* libio/wfileops.c (_IO_wfile_underflow): Remove incorrect test for possible conversion using __codecvt_do_in. * libio/Makefile (tests): Add tst-fgetws. * libio/tst-fgetws.c: New file. * libio/iofgetws.c: Use _IO_ferror_unlocked macros instead of coding the test here.
This commit is contained in:
parent
ca130fe465
commit
5e473a7146
@ -1,5 +1,13 @@
|
|||||||
2001-08-08 Ulrich Drepper <drepper@redhat.com>
|
2001-08-08 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* libio/wfileops.c (_IO_wfile_underflow): Remove incorrect test
|
||||||
|
for possible conversion using __codecvt_do_in.
|
||||||
|
* libio/Makefile (tests): Add tst-fgetws.
|
||||||
|
* libio/tst-fgetws.c: New file.
|
||||||
|
|
||||||
|
* libio/iofgetws.c: Use _IO_ferror_unlocked macros instead of
|
||||||
|
coding the test here.
|
||||||
|
|
||||||
* catgets/open_catalog.c: Rewrite code to assume that the function
|
* catgets/open_catalog.c: Rewrite code to assume that the function
|
||||||
is called at catopen time and not delayed in catgets.
|
is called at catopen time and not delayed in catgets.
|
||||||
* catgets/catgets.c (catopen): Call __open_catalog and fail if that
|
* catgets/catgets.c (catopen): Call __open_catalog and fail if that
|
||||||
|
@ -47,7 +47,8 @@ routines := \
|
|||||||
libc_fatal fmemopen
|
libc_fatal fmemopen
|
||||||
|
|
||||||
tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
|
tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
|
||||||
tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-fopenloc
|
tst_wprintf2 tst-widetext test-fmemopen tst-ext tst-fopenloc \
|
||||||
|
tst-fgetws
|
||||||
test-srcs = test-freopen
|
test-srcs = test-freopen
|
||||||
|
|
||||||
all: # Make this the default target; it will be defined in Rules.
|
all: # Make this the default target; it will be defined in Rules.
|
||||||
@ -82,6 +83,7 @@ tst_wprintf2-ARGS = "Some Text"
|
|||||||
tst-widetext-ENV = LOCPATH=$(common-objpfx)localedata LANGUAGE=C
|
tst-widetext-ENV = LOCPATH=$(common-objpfx)localedata LANGUAGE=C
|
||||||
tst-fopenloc-ENV = LOCPATH=$(common-objpfx)localedata \
|
tst-fopenloc-ENV = LOCPATH=$(common-objpfx)localedata \
|
||||||
MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace
|
MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace
|
||||||
|
tst-fgetws-ENV = LOCPATH=$(common-objpfx)localedata LANGUAGE=C
|
||||||
|
|
||||||
generated = tst-fopenloc.mtrace tst-fopenloc.check
|
generated = tst-fopenloc.mtrace tst-fopenloc.check
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc.
|
/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2001 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
The GNU C Library is free software; you can redistribute it and/or
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
@ -50,8 +50,7 @@ fgetws (buf, n, fp)
|
|||||||
count = _IO_getwline (fp, buf, n - 1, L'\n', 1);
|
count = _IO_getwline (fp, buf, n - 1, L'\n', 1);
|
||||||
/* If we read in some bytes and errno is EAGAIN, that error will
|
/* If we read in some bytes and errno is EAGAIN, that error will
|
||||||
be reported for next read. */
|
be reported for next read. */
|
||||||
if (count == 0 || ((fp->_IO_file_flags & _IO_ERR_SEEN)
|
if (count == 0 || (_IO_ferror_unlocked (fp) && errno != EAGAIN))
|
||||||
&& errno != EAGAIN))
|
|
||||||
result = NULL;
|
result = NULL;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
185
libio/tst-fgetws.c
Normal file
185
libio/tst-fgetws.c
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
/* Taken from the Li18nux base test suite. */
|
||||||
|
|
||||||
|
#define _XOPEN_SOURCE 500
|
||||||
|
#include <errno.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
#define WIDE_STR_LEN 32
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
FILE *fp;
|
||||||
|
wchar_t *ret, wcs[WIDE_STR_LEN];
|
||||||
|
int result = 0;
|
||||||
|
const char il_str1[] = {0xe3, 0x81, '\0'};
|
||||||
|
const char il_str2[] = {'0', '\n', 'A', 'B', 0xe3, 0x81, 'E', '\0'};
|
||||||
|
char name1[] = "/tmp/tst-fgetws.out.XXXXXX";
|
||||||
|
char name2[] = "/tmp/tst-fgetws.out.XXXXXX";
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
puts ("This program runs on de_DE.UTF-8 locale.");
|
||||||
|
if (setlocale (LC_ALL, "de_DE.UTF-8") == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Err: Cannot run on the de_DE.UTF-8 locale");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make a file `il_str1'. */
|
||||||
|
fd = mkstemp (name1);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
printf ("cannot open temp file: %m\n");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if ((fp = fdopen (fd, "w")) == NULL)
|
||||||
|
{
|
||||||
|
printf ("Can't open %s.\n", argv[1]);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
fwrite (il_str1, sizeof (char), sizeof (il_str1), fp);
|
||||||
|
fclose (fp);
|
||||||
|
|
||||||
|
/* Make a file `il_str2'. */
|
||||||
|
fd = mkstemp (name2);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
printf ("cannot open temp file: %m\n");
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
if ((fp = fdopen (fd, "w")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Can't open %s.\n", argv[1]);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
fwrite (il_str2, sizeof (char), sizeof (il_str2), fp);
|
||||||
|
fclose (fp);
|
||||||
|
|
||||||
|
|
||||||
|
/* Test for il_str1. */
|
||||||
|
if ((fp = fopen (name1, "r")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Can't open %s.\n", argv[1]);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
puts ("--");
|
||||||
|
puts ("Read a byte sequence which is invalid as a wide character string.");
|
||||||
|
puts (" bytes: 0xe3, 0x81, '\\0'");
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
ret = fgetws (wcs, WIDE_STR_LEN, fp);
|
||||||
|
|
||||||
|
if (ret == NULL)
|
||||||
|
{
|
||||||
|
puts ("Return Value: NULL");
|
||||||
|
|
||||||
|
if (errno == EILSEQ)
|
||||||
|
puts ("errno = EILSEQ");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("errno = %d\n", errno);
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("Return Value: %p\n", ret);
|
||||||
|
for (i = 0; i < wcslen (wcs) + 1; i++)
|
||||||
|
printf (" wcs[%d] = %04x", i, (unsigned int)wcs[i]);
|
||||||
|
printf ("\n");
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Test for il_str2. */
|
||||||
|
if ((fp = fopen (name2, "r")) == NULL)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Can't open %s.\n", argv[1]);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
puts ("--");
|
||||||
|
puts ("Read a byte sequence which is invalid as a wide character string.");
|
||||||
|
puts (" bytes: '0', '\\n', 'A', 'B', 0xe3, 0x81, 'c', '\\0'");
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
ret = fgetws (wcs, WIDE_STR_LEN, fp);
|
||||||
|
|
||||||
|
if (ret == NULL)
|
||||||
|
{
|
||||||
|
puts ("Return Value: NULL");
|
||||||
|
|
||||||
|
if (errno == EILSEQ)
|
||||||
|
puts ("errno = EILSEQ");
|
||||||
|
else
|
||||||
|
printf ("errno = %d\n", errno);
|
||||||
|
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf ("Return Value: %p\n", ret);
|
||||||
|
for (i = 0; i < wcslen (wcs) + 1; i++)
|
||||||
|
printf (" wcs[%d] = 0x%04x", i, (unsigned int)wcs[i]);
|
||||||
|
printf ("\n");
|
||||||
|
|
||||||
|
for (i = 0; il_str2[i] != '\n'; ++i)
|
||||||
|
if ((wchar_t) il_str2[i] != wcs[i])
|
||||||
|
{
|
||||||
|
puts ("read string not correct");
|
||||||
|
result = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (il_str2[i] == '\n')
|
||||||
|
{
|
||||||
|
if (wcs[i] != L'\n')
|
||||||
|
{
|
||||||
|
puts ("newline missing");
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
else if (wcs[i + 1] != L'\0')
|
||||||
|
{
|
||||||
|
puts ("read string not NUL-terminated");
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
puts ("\nsecond line");
|
||||||
|
errno = 0;
|
||||||
|
ret = fgetws (wcs, WIDE_STR_LEN, fp);
|
||||||
|
|
||||||
|
if (ret == NULL)
|
||||||
|
{
|
||||||
|
puts ("Return Value: NULL");
|
||||||
|
|
||||||
|
if (errno == EILSEQ)
|
||||||
|
puts ("errno = EILSEQ");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("errno = %d\n", errno);
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("Return Value: %p\n", ret);
|
||||||
|
for (i = 0; i < wcslen (wcs) + 1; i++)
|
||||||
|
printf (" wcs[%d] = 0x%04x", i, (unsigned int)wcs[i]);
|
||||||
|
printf ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose (fp);
|
||||||
|
|
||||||
|
unlink (name1);
|
||||||
|
unlink (name2);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
@ -157,34 +157,28 @@ _IO_wfile_underflow (fp)
|
|||||||
/* Maybe there is something left in the external buffer. */
|
/* Maybe there is something left in the external buffer. */
|
||||||
if (fp->_IO_read_ptr < fp->_IO_read_end)
|
if (fp->_IO_read_ptr < fp->_IO_read_end)
|
||||||
{
|
{
|
||||||
/* Convert it. */
|
/* There is more in the external. Convert it. */
|
||||||
size_t avail_bytes = fp->_IO_read_end - fp->_IO_read_ptr;
|
const char *read_stop = (const char *) fp->_IO_read_ptr;
|
||||||
|
|
||||||
if (avail_bytes >= (*cd->__codecvt_do_max_length) (cd))
|
fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
|
||||||
|
status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
|
||||||
|
fp->_IO_read_ptr, fp->_IO_read_end,
|
||||||
|
&read_stop,
|
||||||
|
fp->_wide_data->_IO_read_end,
|
||||||
|
fp->_wide_data->_IO_buf_end,
|
||||||
|
&fp->_wide_data->_IO_read_end);
|
||||||
|
|
||||||
|
fp->_IO_read_ptr = (char *) read_stop;
|
||||||
|
|
||||||
|
/* If we managed to generate some text return the next character. */
|
||||||
|
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
||||||
|
return *fp->_wide_data->_IO_read_ptr;
|
||||||
|
|
||||||
|
if (status == __codecvt_error)
|
||||||
{
|
{
|
||||||
/* There is more in the external. */
|
__set_errno (EILSEQ);
|
||||||
const char *read_stop = (const char *) fp->_IO_read_ptr;
|
fp->_flags |= _IO_ERR_SEEN;
|
||||||
|
return WEOF;
|
||||||
fp->_wide_data->_IO_last_state = fp->_wide_data->_IO_state;
|
|
||||||
status = (*cd->__codecvt_do_in) (cd, &fp->_wide_data->_IO_state,
|
|
||||||
fp->_IO_read_ptr, fp->_IO_read_end,
|
|
||||||
&read_stop,
|
|
||||||
fp->_wide_data->_IO_read_end,
|
|
||||||
fp->_wide_data->_IO_buf_end,
|
|
||||||
&fp->_wide_data->_IO_read_end);
|
|
||||||
|
|
||||||
fp->_IO_read_ptr = (char *) read_stop;
|
|
||||||
|
|
||||||
/* If we managed to generate some text return the next character. */
|
|
||||||
if (fp->_wide_data->_IO_read_ptr < fp->_wide_data->_IO_read_end)
|
|
||||||
return *fp->_wide_data->_IO_read_ptr;
|
|
||||||
|
|
||||||
if (status == __codecvt_error)
|
|
||||||
{
|
|
||||||
__set_errno (EILSEQ);
|
|
||||||
fp->_flags |= _IO_ERR_SEEN;
|
|
||||||
return WEOF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the remaining content of the read buffer to the beginning. */
|
/* Move the remaining content of the read buffer to the beginning. */
|
||||||
|
Loading…
Reference in New Issue
Block a user