about summary refs log tree commit diff
path: root/stdio-common/vfprintf.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-07-20 08:56:12 +0000
committerUlrich Drepper <drepper@redhat.com>2000-07-20 08:56:12 +0000
commit9c38a6899957746cbf2c0c04d110626a9271d51a (patch)
tree7baeb90b3aff1cf0acf63fed32577f3a9ad17764 /stdio-common/vfprintf.c
parent4e8286acfa4224ac9ccfb07e90b8fd70fab1467e (diff)
downloadglibc-9c38a6899957746cbf2c0c04d110626a9271d51a.tar.gz
glibc-9c38a6899957746cbf2c0c04d110626a9271d51a.tar.xz
glibc-9c38a6899957746cbf2c0c04d110626a9271d51a.zip
Update.
2000-07-20  Ulrich Drepper  <drepper@redhat.com>

	* libio/Makefile (tests): Add tst_wprintf2.
	(tst_wprintf2-ARGS): Define.
	* libio/tst_wprintf2.c: New file.
	Based on a test case by Yoshito Kawada <KAWADA@jp.ibm.com>.

	* libio/wfiledoalloc.c: Only allocate external buffer if this
	hasn't happened yet.

	* libio/wfileops.c (_IO_wdo_write): Overflow only if there is really
	something in the buffer.  gconv call can write up to end of the
	buffer, not only _IO_write_end.
	(_IO_wfile_overflow): Allocate also external buffer.

	* stdio-common/vfprintf.c (process_string_arg): Handle multibyte
	strings with precision in vfwprintf correctly.
	* stdio-common/vfprintf.c: Fix completely broken handling of
	unbuffered wide character streams.
	Reported by Yoshito Kawada <KAWADA@jp.ibm.com>.
Diffstat (limited to 'stdio-common/vfprintf.c')
-rw-r--r--stdio-common/vfprintf.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index 32ad9d85ab..23981d18cd 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -1030,14 +1030,14 @@ vfprintf (FILE *s, const CHAR_T *format, va_list ap)
 	    const char *mbs = (const char *) string;			      \
 	    mbstate_t mbstate;						      \
 									      \
-	    len = prec == -1 ? strnlen (mbs, prec) : strlen (mbs);	      \
+	    len = prec != -1 ? strnlen (mbs, prec) : strlen (mbs);	      \
 									      \
 	    /* Allocate dynamically an array which definitely is long	      \
 	       enough for the wide character version.  */		      \
-	    string = (CHAR_T *) alloca ((len + 1) * sizeof (wchar_t));	      \
+	    string = (CHAR_T *) alloca (len * sizeof (wchar_t));	      \
 									      \
 	    memset (&mbstate, '\0', sizeof (mbstate_t));		      \
-	    len = __mbsrtowcs (string, &mbs, len + 1, &mbstate);	      \
+	    len = __mbsrtowcs (string, &mbs, len, &mbstate);		      \
 	    if (len == (size_t) -1)					      \
 	      {								      \
 		/* Illegal multibyte character.  */			      \
@@ -1919,6 +1919,9 @@ group_number (CHAR_T *w, CHAR_T *rear_ptr, const char *grouping,
 struct helper_file
   {
     struct _IO_FILE_plus _f;
+#ifdef COMPILE_WPRINTF
+    struct _IO_wide_data _wide_data;
+#endif
     _IO_FILE *_put_stream;
 #ifdef _IO_MTSAFE_IO
     _IO_lock_t lock;
@@ -1948,6 +1951,29 @@ _IO_helper_overflow (_IO_FILE *s, int c)
   return PUTC (c, s);
 }
 
+#ifdef COMPILE_WPRINTF
+static const struct _IO_jump_t _IO_helper_jumps =
+{
+  JUMP_INIT_DUMMY,
+  JUMP_INIT (finish, _IO_wdefault_finish),
+  JUMP_INIT (overflow, _IO_helper_overflow),
+  JUMP_INIT (underflow, _IO_default_underflow),
+  JUMP_INIT (uflow, _IO_default_uflow),
+  JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wdefault_pbackfail),
+  JUMP_INIT (xsputn, _IO_wdefault_xsputn),
+  JUMP_INIT (xsgetn, _IO_wdefault_xsgetn),
+  JUMP_INIT (seekoff, _IO_default_seekoff),
+  JUMP_INIT (seekpos, _IO_default_seekpos),
+  JUMP_INIT (setbuf,(_IO_setbuf_t)  _IO_wdefault_setbuf),
+  JUMP_INIT (sync, _IO_default_sync),
+  JUMP_INIT (doallocate, _IO_wdefault_doallocate),
+  JUMP_INIT (read, _IO_default_read),
+  JUMP_INIT (write, _IO_default_write),
+  JUMP_INIT (seek, _IO_default_seek),
+  JUMP_INIT (close, _IO_default_close),
+  JUMP_INIT (stat, _IO_default_stat)
+};
+#else
 static const struct _IO_jump_t _IO_helper_jumps =
 {
   JUMP_INIT_DUMMY,
@@ -1969,6 +1995,7 @@ static const struct _IO_jump_t _IO_helper_jumps =
   JUMP_INIT (close, _IO_default_close),
   JUMP_INIT (stat, _IO_default_stat)
 };
+#endif
 
 static int
 internal_function
@@ -1983,6 +2010,7 @@ buffered_vfprintf (register _IO_FILE *s, const CHAR_T *format,
   /* Initialize helper.  */
   helper._put_stream = s;
 #ifdef COMPILE_WPRINTF
+  hp->_wide_data = &helper._wide_data;
   _IO_wsetp (hp, buf, buf + sizeof buf / sizeof (CHAR_T));
   hp->_mode = 1;
 #else