mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-25 14:30:06 +00:00
[BZ #2337]
2006-12-13 Ulrich Drepper <drepper@redhat.com> [BZ #2337] * libio/Makefile (tests): Add tst-setvbuf1. * libio/tst-setvbuf1.c: New file. 2006-12-08 Jakub Jelinek <jakub@redhat.com> [BZ #2337] * libio/genops.c (__uflow): Fix a typo. * libio/wfiledoalloc.c (_IO_wfile_doallocate): Don't stat nor set _IO_LINE_BUF bit here. Size the wide buffer based on the narrow buffer size. 2006-11-24 Jakub Jelinek <jakub@redhat.com> [BZ #2337] * libio/libio.h (_IO_FLAGS2_USER_WBUF): Define. * libio/wgenops.c (_IO_wsetb, _IO_wdefault_finish): Test and set _IO_FLAGS2_USER_WBUF bit in _flags2 instead of _IO_USER_BUF bit in _flags. * libio/wstrops.c (_IO_wstr_overflow, enlarge_userbuf, _IO_wstr_finish): Likewise. * libio/wmemstream.c (open_wmemstream): Likewise. * libio/fileops.c (_IO_new_file_close_it): Call _IO_set[bgp] even for wide streams.
This commit is contained in:
parent
f72386ad7c
commit
1e88bd0f1b
27
ChangeLog
27
ChangeLog
@ -1,3 +1,30 @@
|
|||||||
|
2006-12-13 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
[BZ #2337]
|
||||||
|
* libio/Makefile (tests): Add tst-setvbuf1.
|
||||||
|
* libio/tst-setvbuf1.c: New file.
|
||||||
|
|
||||||
|
2006-12-08 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
[BZ #2337]
|
||||||
|
* libio/genops.c (__uflow): Fix a typo.
|
||||||
|
* libio/wfiledoalloc.c (_IO_wfile_doallocate): Don't stat
|
||||||
|
nor set _IO_LINE_BUF bit here. Size the wide buffer based on
|
||||||
|
the narrow buffer size.
|
||||||
|
|
||||||
|
2006-11-24 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
|
[BZ #2337]
|
||||||
|
* libio/libio.h (_IO_FLAGS2_USER_WBUF): Define.
|
||||||
|
* libio/wgenops.c (_IO_wsetb, _IO_wdefault_finish): Test and set
|
||||||
|
_IO_FLAGS2_USER_WBUF bit in _flags2 instead of _IO_USER_BUF bit
|
||||||
|
in _flags.
|
||||||
|
* libio/wstrops.c (_IO_wstr_overflow, enlarge_userbuf,
|
||||||
|
_IO_wstr_finish): Likewise.
|
||||||
|
* libio/wmemstream.c (open_wmemstream): Likewise.
|
||||||
|
* libio/fileops.c (_IO_new_file_close_it): Call _IO_set[bgp]
|
||||||
|
even for wide streams.
|
||||||
|
|
||||||
2006-12-13 Jakub Jelinek <jakub@redhat.com>
|
2006-12-13 Jakub Jelinek <jakub@redhat.com>
|
||||||
|
|
||||||
* sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S: Include
|
* sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S: Include
|
||||||
|
@ -57,7 +57,8 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
|
|||||||
bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 tst-fopenloc2 \
|
bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 tst-fopenloc2 \
|
||||||
tst-memstream1 tst-memstream2 \
|
tst-memstream1 tst-memstream2 \
|
||||||
tst-wmemstream1 tst-wmemstream2 \
|
tst-wmemstream1 tst-wmemstream2 \
|
||||||
bug-memstream1 bug-wmemstream1
|
bug-memstream1 bug-wmemstream1 \
|
||||||
|
tst-setvbuf1
|
||||||
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.
|
||||||
|
@ -174,14 +174,8 @@ _IO_new_file_close_it (fp)
|
|||||||
close_status = _IO_SYSCLOSE (fp);
|
close_status = _IO_SYSCLOSE (fp);
|
||||||
|
|
||||||
/* Free buffer. */
|
/* Free buffer. */
|
||||||
if (fp->_mode <= 0)
|
|
||||||
{
|
|
||||||
INTUSE(_IO_setb) (fp, NULL, NULL, 0);
|
|
||||||
_IO_setg (fp, NULL, NULL, NULL);
|
|
||||||
_IO_setp (fp, NULL, NULL);
|
|
||||||
}
|
|
||||||
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
#if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T
|
||||||
else
|
if (fp->_mode > 0)
|
||||||
{
|
{
|
||||||
if (_IO_have_wbackup (fp))
|
if (_IO_have_wbackup (fp))
|
||||||
INTUSE(_IO_free_wbackup_area) (fp);
|
INTUSE(_IO_free_wbackup_area) (fp);
|
||||||
@ -190,6 +184,9 @@ _IO_new_file_close_it (fp)
|
|||||||
_IO_wsetp (fp, NULL, NULL);
|
_IO_wsetp (fp, NULL, NULL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
INTUSE(_IO_setb) (fp, NULL, NULL, 0);
|
||||||
|
_IO_setg (fp, NULL, NULL, NULL);
|
||||||
|
_IO_setp (fp, NULL, NULL);
|
||||||
|
|
||||||
INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);
|
INTUSE(_IO_un_link) ((struct _IO_FILE_plus *) fp);
|
||||||
fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
|
fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS;
|
||||||
|
@ -367,7 +367,7 @@ __uflow (fp)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fp->_mode == 0)
|
if (fp->_mode == 0)
|
||||||
_IO_fwide (fp, -11);
|
_IO_fwide (fp, -1);
|
||||||
if (_IO_in_put_mode (fp))
|
if (_IO_in_put_mode (fp))
|
||||||
if (INTUSE(_IO_switch_to_get_mode) (fp) == EOF)
|
if (INTUSE(_IO_switch_to_get_mode) (fp) == EOF)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
@ -142,6 +142,7 @@
|
|||||||
#ifdef _LIBC
|
#ifdef _LIBC
|
||||||
# define _IO_FLAGS2_FORTIFY 4
|
# define _IO_FLAGS2_FORTIFY 4
|
||||||
#endif
|
#endif
|
||||||
|
#define _IO_FLAGS2_USER_WBUF 8
|
||||||
|
|
||||||
/* These are "formatting flags" matching the iostream fmtflags enum values. */
|
/* These are "formatting flags" matching the iostream fmtflags enum values. */
|
||||||
#define _IO_SKIPWS 01
|
#define _IO_SKIPWS 01
|
||||||
|
39
libio/tst-setvbuf1.c
Normal file
39
libio/tst-setvbuf1.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* Dereived from the test case in BZ #2337. */
|
||||||
|
#include <errno.h>
|
||||||
|
#include <error.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <locale.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
|
||||||
|
static char buf[512] __attribute__ ((aligned (4096)));
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
setlocale (LC_ALL, "de_DE.UTF-8");
|
||||||
|
|
||||||
|
FILE *fp = fdopen (dup (STDOUT_FILENO), "a");
|
||||||
|
if (fp == NULL)
|
||||||
|
error (EXIT_FAILURE, errno, "fdopen(,\"a\")");
|
||||||
|
|
||||||
|
setvbuf (fp, buf, _IOFBF, sizeof (buf));
|
||||||
|
|
||||||
|
/* fwprintf to unbuffered stream. */
|
||||||
|
fwprintf (fp, L"hello.\n");
|
||||||
|
|
||||||
|
fclose (fp);
|
||||||
|
|
||||||
|
/* touch my buffer */
|
||||||
|
buf[45] = 'a';
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
#include "../test-skeleton.c"
|
@ -1,4 +1,5 @@
|
|||||||
/* Copyright (C) 1993, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
|
/* Copyright (C) 1993, 1997, 1999, 2000, 2002, 2006
|
||||||
|
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
|
||||||
@ -85,35 +86,20 @@ _IO_wfile_doallocate (fp)
|
|||||||
_IO_FILE *fp;
|
_IO_FILE *fp;
|
||||||
{
|
{
|
||||||
_IO_size_t size;
|
_IO_size_t size;
|
||||||
int couldbetty;
|
|
||||||
wchar_t *p;
|
wchar_t *p;
|
||||||
struct _G_stat64 st;
|
|
||||||
|
|
||||||
/* Allocate room for the external buffer. */
|
/* Allocate room for the external buffer. */
|
||||||
if (fp->_IO_buf_base == NULL)
|
if (fp->_IO_buf_base == NULL)
|
||||||
INTUSE(_IO_file_doallocate) (fp);
|
INTUSE(_IO_file_doallocate) (fp);
|
||||||
|
|
||||||
if (fp->_fileno < 0 || _IO_SYSSTAT (fp, &st) < 0)
|
/* If narrow buffer is user allocated (set by setvbuf etc.),
|
||||||
{
|
use that size as the size of the wide buffer, when it is
|
||||||
couldbetty = 0;
|
allocated by _IO_file_doallocate, multiply that by size
|
||||||
size = _IO_BUFSIZ;
|
of the wide character. */
|
||||||
#if 0
|
size = fp->_IO_buf_end - fp->_IO_buf_base;
|
||||||
/* do not try to optimise fseek() */
|
if ((fp->_flags & _IO_USER_BUF))
|
||||||
fp->_flags |= __SNPT;
|
size = (size + sizeof (wchar_t) - 1) / sizeof (wchar_t);
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
couldbetty = S_ISCHR (st.st_mode);
|
|
||||||
#if _IO_HAVE_ST_BLKSIZE
|
|
||||||
size = st.st_blksize <= 0 ? _IO_BUFSIZ : st.st_blksize;
|
|
||||||
#else
|
|
||||||
size = _IO_BUFSIZ;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
ALLOC_WBUF (p, size * sizeof (wchar_t), EOF);
|
ALLOC_WBUF (p, size * sizeof (wchar_t), EOF);
|
||||||
INTUSE(_IO_wsetb) (fp, p, p + size, 1);
|
INTUSE(_IO_wsetb) (fp, p, p + size, 1);
|
||||||
if (couldbetty && isatty (fp->_fileno))
|
|
||||||
fp->_flags |= _IO_LINE_BUF;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -115,14 +115,14 @@ _IO_wsetb (f, b, eb, a)
|
|||||||
wchar_t *eb;
|
wchar_t *eb;
|
||||||
int a;
|
int a;
|
||||||
{
|
{
|
||||||
if (f->_wide_data->_IO_buf_base && !(f->_flags & _IO_USER_BUF))
|
if (f->_wide_data->_IO_buf_base && !(f->_flags2 & _IO_FLAGS2_USER_WBUF))
|
||||||
FREE_BUF (f->_wide_data->_IO_buf_base, _IO_wblen (f) * sizeof (wchar_t));
|
FREE_BUF (f->_wide_data->_IO_buf_base, _IO_wblen (f) * sizeof (wchar_t));
|
||||||
f->_wide_data->_IO_buf_base = b;
|
f->_wide_data->_IO_buf_base = b;
|
||||||
f->_wide_data->_IO_buf_end = eb;
|
f->_wide_data->_IO_buf_end = eb;
|
||||||
if (a)
|
if (a)
|
||||||
f->_flags &= ~_IO_USER_BUF;
|
f->_flags2 &= ~_IO_FLAGS2_USER_WBUF;
|
||||||
else
|
else
|
||||||
f->_flags |= _IO_USER_BUF;
|
f->_flags2 |= _IO_FLAGS2_USER_WBUF;
|
||||||
}
|
}
|
||||||
INTDEF(_IO_wsetb)
|
INTDEF(_IO_wsetb)
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ _IO_wdefault_finish (fp, dummy)
|
|||||||
int dummy;
|
int dummy;
|
||||||
{
|
{
|
||||||
struct _IO_marker *mark;
|
struct _IO_marker *mark;
|
||||||
if (fp->_wide_data->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
|
if (fp->_wide_data->_IO_buf_base && !(fp->_flags2 & _IO_FLAGS2_USER_WBUF))
|
||||||
{
|
{
|
||||||
FREE_BUF (fp->_wide_data->_IO_buf_base,
|
FREE_BUF (fp->_wide_data->_IO_buf_base,
|
||||||
_IO_wblen (fp) * sizeof (wchar_t));
|
_IO_wblen (fp) * sizeof (wchar_t));
|
||||||
|
@ -92,7 +92,7 @@ open_wmemstream (bufloc, sizeloc)
|
|||||||
_IO_fwide (&new_f->fp._sf._sbf._f, 1);
|
_IO_fwide (&new_f->fp._sf._sbf._f, 1);
|
||||||
_IO_wstr_init_static (&new_f->fp._sf._sbf._f, buf,
|
_IO_wstr_init_static (&new_f->fp._sf._sbf._f, buf,
|
||||||
_IO_BUFSIZ / sizeof (wchar_t), buf);
|
_IO_BUFSIZ / sizeof (wchar_t), buf);
|
||||||
new_f->fp._sf._sbf._f._flags &= ~_IO_USER_BUF;
|
new_f->fp._sf._sbf._f._flags2 &= ~_IO_FLAGS2_USER_WBUF;
|
||||||
new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc;
|
new_f->fp._sf._s._allocate_buffer = (_IO_alloc_type) malloc;
|
||||||
new_f->fp._sf._s._free_buffer = (_IO_free_type) free;
|
new_f->fp._sf._s._free_buffer = (_IO_free_type) free;
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ _IO_wstr_overflow (fp, c)
|
|||||||
pos = fp->_wide_data->_IO_write_ptr - fp->_wide_data->_IO_write_base;
|
pos = fp->_wide_data->_IO_write_ptr - fp->_wide_data->_IO_write_base;
|
||||||
if (pos >= (_IO_size_t) (_IO_wblen (fp) + flush_only))
|
if (pos >= (_IO_size_t) (_IO_wblen (fp) + flush_only))
|
||||||
{
|
{
|
||||||
if (fp->_flags & _IO_USER_BUF) /* not allowed to enlarge */
|
if (fp->_flags2 & _IO_FLAGS2_USER_WBUF) /* not allowed to enlarge */
|
||||||
return WEOF;
|
return WEOF;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -182,7 +182,7 @@ enlarge_userbuf (_IO_FILE *fp, _IO_off64_t offset, int reading)
|
|||||||
_IO_ssize_t oldend = wd->_IO_write_end - wd->_IO_write_base;
|
_IO_ssize_t oldend = wd->_IO_write_end - wd->_IO_write_base;
|
||||||
|
|
||||||
/* Try to enlarge the buffer. */
|
/* Try to enlarge the buffer. */
|
||||||
if (fp->_flags & _IO_USER_BUF)
|
if (fp->_flags2 & _IO_FLAGS2_USER_WBUF)
|
||||||
/* User-provided buffer. */
|
/* User-provided buffer. */
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
@ -335,7 +335,7 @@ _IO_wstr_finish (fp, dummy)
|
|||||||
_IO_FILE *fp;
|
_IO_FILE *fp;
|
||||||
int dummy;
|
int dummy;
|
||||||
{
|
{
|
||||||
if (fp->_wide_data->_IO_buf_base && !(fp->_flags & _IO_USER_BUF))
|
if (fp->_wide_data->_IO_buf_base && !(fp->_flags2 & _IO_FLAGS2_USER_WBUF))
|
||||||
(((_IO_strfile *) fp)->_s._free_buffer) (fp->_wide_data->_IO_buf_base);
|
(((_IO_strfile *) fp)->_s._free_buffer) (fp->_wide_data->_IO_buf_base);
|
||||||
fp->_wide_data->_IO_buf_base = NULL;
|
fp->_wide_data->_IO_buf_base = NULL;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user