diff options
Diffstat (limited to 'libio')
38 files changed, 752 insertions, 111 deletions
diff --git a/libio/Makefile b/libio/Makefile index a97623f14a..e9c1d522fd 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1995-2002, 2003, 2004 Free Software Foundation, Inc. +# Copyright (C) 1995-2002,2003,2004,2006 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -22,7 +22,7 @@ subdir := libio headers := stdio.h libio.h _G_config.h bits/stdio.h bits/stdio-lock.h \ - bits/sys_errlist.h bits/stdio2.h + bits/sys_errlist.h bits/stdio2.h bits/stdio-ldbl.h bits/libio-ldbl.h routines := \ filedoalloc iofclose iofdopen iofflush iofgetpos iofgets iofopen \ @@ -35,7 +35,7 @@ routines := \ iofputws iofputws_u iogetwline iowpadn ioungetwc putwc putwc_u \ putwchar putwchar_u putchar putchar_u fwprintf swprintf vwprintf \ wprintf wscanf fwscanf vwscanf vswprintf iovswscanf swscanf wgenops \ - wstrops wfileops iofwide fwide \ + wstrops wfileops iofwide fwide wmemstream \ \ clearerr feof ferror fileno fputc freopen fseek getc getchar \ memstream pclose putc putchar rewind setbuf setlinebuf vasprintf \ @@ -54,7 +54,9 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \ tst-mmap-eofsync tst-mmap-fflushsync bug-mmap-fflush \ tst-mmap2-eofsync tst-mmap-offend bug-fopena+ bug-wfflush \ - bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 + bug-ungetc2 bug-ftell bug-ungetc3 bug-ungetc4 tst-fopenloc2 \ + tst-memstream1 tst-memstream2 \ + tst-wmemstream1 tst-wmemstream2 test-srcs = test-freopen all: # Make this the default target; it will be defined in Rules. diff --git a/libio/Versions b/libio/Versions index c870494872..e7a96daca5 100644 --- a/libio/Versions +++ b/libio/Versions @@ -145,6 +145,9 @@ libc { # w* wprintf; wscanf; } + GLIBC_2.4 { + open_wmemstream; + } GLIBC_PRIVATE { # Used by NPTL and librt __libc_fatal; diff --git a/libio/bits/libio-ldbl.h b/libio/bits/libio-ldbl.h new file mode 100644 index 0000000000..6e02115f4a --- /dev/null +++ b/libio/bits/libio-ldbl.h @@ -0,0 +1,27 @@ +/* -mlong-double-64 compatibility mode for libio functions. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _IO_STDIO_H +# error "Never include <bits/libio-ldbl.h> directly; use <libio.h> instead." +#endif + +__LDBL_REDIR_DECL (_IO_vfscanf) +__LDBL_REDIR_DECL (_IO_vfprintf) +__LDBL_REDIR_DECL (_IO_vfwscanf) +__LDBL_REDIR_DECL (_IO_vfwprintf) diff --git a/libio/bits/stdio-ldbl.h b/libio/bits/stdio-ldbl.h new file mode 100644 index 0000000000..7a4291225e --- /dev/null +++ b/libio/bits/stdio-ldbl.h @@ -0,0 +1,74 @@ +/* -mlong-double-64 compatibility mode for stdio functions. + Copyright (C) 2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _STDIO_H +# error "Never include <bits/stdio-ldbl.h> directly; use <stdio.h> instead." +#endif + +__BEGIN_NAMESPACE_STD +__LDBL_REDIR_DECL (fprintf) +__LDBL_REDIR_DECL (printf) +__LDBL_REDIR_DECL (sprintf) +__LDBL_REDIR_DECL (vfprintf) +__LDBL_REDIR_DECL (vprintf) +__LDBL_REDIR_DECL (vsprintf) +__LDBL_REDIR_DECL (fscanf) +__LDBL_REDIR_DECL (scanf) +__LDBL_REDIR_DECL (sscanf) +__END_NAMESPACE_STD + +#if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 +__BEGIN_NAMESPACE_C99 +__LDBL_REDIR_DECL (snprintf) +__LDBL_REDIR_DECL (vsnprintf) +__END_NAMESPACE_C99 +#endif + +#ifdef __USE_ISOC99 +__BEGIN_NAMESPACE_C99 +__LDBL_REDIR_DECL (vfscanf) +__LDBL_REDIR_DECL (vsscanf) +__LDBL_REDIR_DECL (vscanf) +__END_NAMESPACE_C99 +#endif + +#ifdef __USE_GNU +__LDBL_REDIR_DECL (vdprintf) +__LDBL_REDIR_DECL (dprintf) +__LDBL_REDIR_DECL (vasprintf) +__LDBL_REDIR_DECL (__asprintf) +__LDBL_REDIR_DECL (asprintf) +__LDBL_REDIR_DECL (obstack_printf) +__LDBL_REDIR_DECL (obstack_vprintf) +#endif + +#if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus +__LDBL_REDIR_DECL (__sprintf_chk) +__LDBL_REDIR_DECL (__vsprintf_chk) +# if defined __USE_BSD || defined __USE_ISOC99 || defined __USE_UNIX98 +__LDBL_REDIR_DECL (__snprintf_chk) +__LDBL_REDIR_DECL (__vsnprintf_chk) +# endif +# if __USE_FORTIFY_LEVEL > 1 +__LDBL_REDIR_DECL (__fprintf_chk) +__LDBL_REDIR_DECL (__printf_chk) +__LDBL_REDIR_DECL (__vfprintf_chk) +__LDBL_REDIR_DECL (__vprintf_chk) +# endif +#endif diff --git a/libio/fileops.c b/libio/fileops.c index 74d5cd0dbc..cf7fd65421 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997-2004, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1995, 1997-2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Per Bothner <bothner@cygnus.com>. @@ -399,6 +399,9 @@ _IO_new_file_fopen (fp, filename, mode, is32not64) /* And now the transliteration. */ cc->__cd_out.__cd.__data[0].__trans = &__libio_translit; + /* From now on use the wide character callback functions. */ + ((struct _IO_FILE_plus *) fp)->vtable = fp->_wide_data->_wide_vtable; + /* Set the mode now. */ result->_mode = 1; } diff --git a/libio/fputwc.c b/libio/fputwc.c index 8c749435a0..42cf9d716c 100644 --- a/libio/fputwc.c +++ b/libio/fputwc.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1996,1997,1998,1999,2003 Free Software Foundation, Inc. +/* Copyright (C) 1993,1996,1997,1998,1999,2003, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -33,7 +33,7 @@ fputwc (wc, fp) wchar_t wc; _IO_FILE *fp; { - int result; + wint_t result; CHECK_FILE (fp, EOF); _IO_acquire_lock (fp); if (_IO_fwide (fp, 1) < 0) diff --git a/libio/fputwc_u.c b/libio/fputwc_u.c index 93cbcab3d3..0478410cca 100644 --- a/libio/fputwc_u.c +++ b/libio/fputwc_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996, 1997, 1999 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1996, 1997, 1999, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -35,7 +35,7 @@ fputwc_unlocked (wc, fp) wchar_t wc; _IO_FILE *fp; { - CHECK_FILE (fp, EOF); + CHECK_FILE (fp, WEOF); if (_IO_fwide (fp, 1) < 0) return WEOF; return _IO_putwc_unlocked (wc, fp); diff --git a/libio/fwprintf.c b/libio/fwprintf.c index cadeda04ab..9d9111d7c6 100644 --- a/libio/fwprintf.c +++ b/libio/fwprintf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991, 1997, 1999, 2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1997, 1999, 2000, 2001, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -35,4 +37,4 @@ __fwprintf (FILE *stream, const wchar_t *format, ...) return done; } -weak_alias (__fwprintf, fwprintf) +ldbl_weak_alias (__fwprintf, fwprintf) diff --git a/libio/fwscanf.c b/libio/fwscanf.c index 411e1825c0..17296fa3d6 100644 --- a/libio/fwscanf.c +++ b/libio/fwscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1997, 1999, 2000 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1997, 1999, 2000, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,6 +16,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -23,7 +24,7 @@ /* Read formatted input from STREAM according to the format string FORMAT. */ /* VARARGS2 */ int -fwscanf (FILE *stream, const wchar_t *format, ...) +__fwscanf (FILE *stream, const wchar_t *format, ...) { va_list arg; int done; @@ -34,3 +35,4 @@ fwscanf (FILE *stream, const wchar_t *format, ...) return done; } +ldbl_strong_alias (__fwscanf, fwscanf) diff --git a/libio/genops.c b/libio/genops.c index 741ed77f86..da29ade4e6 100644 --- a/libio/genops.c +++ b/libio/genops.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1993,1995,1997-2002, 2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2002, 2003, 2004, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -657,6 +658,7 @@ _IO_no_init (fp, flags, orientation, wd, jmp) fp->_wide_data->_wide_vtable = jmp; } #endif + fp->_freeres_list = NULL; } int @@ -914,10 +916,27 @@ INTDEF(_IO_flush_all_linebuffered) weak_alias (_IO_flush_all_linebuffered, _flushlbf) #endif + +/* The following is a bit tricky. In general, we want to unbuffer the + streams so that all output which follows is seen. If we are not + looking for memory leaks it does not make much sense to free the + actual buffer because this will happen anyway once the program + terminated. If we do want to look for memory leaks we have to free + the buffers. Whether something is freed is determined by the + function sin the libc_freeres section. Those are called as part of + the atexit routine, just like _IO_cleanup. The problem is we do + not know whether the freeres code is called first or _IO_cleanup. + if the former is the case, we set the DEALLOC_BUFFER variable to + true and _IO_unbuffer_write will take care of the rest. If + _IO_unbuffer_write is called first we add the streams to a list + which the freeres function later can walk through. */ static void _IO_unbuffer_write (void); +static bool dealloc_buffers; +static _IO_FILE *freeres_list; + static void -_IO_unbuffer_write () +_IO_unbuffer_write (void) { struct _IO_FILE *fp; for (fp = (_IO_FILE *) INTUSE(_IO_list_all); fp; fp = fp->_chain) @@ -927,7 +946,32 @@ _IO_unbuffer_write () || (fp->_flags & _IO_IS_APPENDING)) /* Iff stream is un-orientated, it wasn't used. */ && fp->_mode != 0) - _IO_SETBUF (fp, NULL, 0); + { + int cnt; +#define MAXTRIES 2 + for (cnt = 0; cnt < MAXTRIES; ++cnt) + if (_IO_lock_trylock (*fp->_lock) == 0) + break; + else + /* Give the other thread time to finish up its use of the + stream. */ + __sched_yield (); + + if (! dealloc_buffers && !(fp->_flags & _IO_USER_BUF)) + { + fp->_flags |= _IO_USER_BUF; + + fp->_freeres_list = freeres_list; + freeres_list = fp; + fp->_freeres_buf = fp->_IO_buf_base; + fp->_freeres_size = _IO_blen (fp); + } + + _IO_SETBUF (fp, NULL, 0); + + if (cnt < MAXTRIES) + _IO_lock_unlock (*fp->_lock); + } /* Make sure that never again the wide char functions can be used. */ @@ -935,11 +979,25 @@ _IO_unbuffer_write () } } + +libc_freeres_fn (buffer_free) +{ + dealloc_buffers = true; + + while (freeres_list != NULL) + { + FREE_BUF (freeres_list->_freeres_buf, freeres_list->_freeres_size); + + freeres_list = freeres_list->_freeres_list; + } +} + + int _IO_cleanup () { /* We do *not* want locking. Some threads might use streams but - that is there problem, we flush them underneath them. */ + that is their problem, we flush them underneath them. */ int result = _IO_flush_all_lockp (0); /* We currently don't have a reliable mechanism for making sure that diff --git a/libio/getwc_u.c b/libio/getwc_u.c index bdad3c8bf3..229343cc61 100644 --- a/libio/getwc_u.c +++ b/libio/getwc_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1996,1997,1999,2000 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1996,1997,1999,2000, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -33,7 +33,7 @@ wint_t __getwc_unlocked (FILE *fp) { - CHECK_FILE (fp, EOF); + CHECK_FILE (fp, WEOF); return _IO_getwc_unlocked (fp); } diff --git a/libio/ioungetwc.c b/libio/ioungetwc.c index 00d3e965b5..f7b6866617 100644 --- a/libio/ioungetwc.c +++ b/libio/ioungetwc.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1996, 1997, 1998, 1999, 2001, 2002, 2003 +/* Copyright (C) 1993, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -34,7 +34,7 @@ ungetwc (c, fp) wint_t c; _IO_FILE *fp; { - int result; + wint_t result; CHECK_FILE (fp, WEOF); _IO_acquire_lock (fp); _IO_fwide (fp, 1); diff --git a/libio/iovdprintf.c b/libio/iovdprintf.c index e81d870ca7..edab849a44 100644 --- a/libio/iovdprintf.c +++ b/libio/iovdprintf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1995,1997-2000,2001,2002,2003 Free Software Foundation, Inc. +/* Copyright (C) 1995, 1997-2000, 2001, 2002, 2003, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -25,7 +26,7 @@ This exception applies to code released by its copyright holders in files containing the exception. */ -#include "libioP.h" +#include <libioP.h> #include <stdio_ext.h> int @@ -63,7 +64,4 @@ _IO_vdprintf (d, format, arg) return done; } - -#ifdef weak_alias -weak_alias (_IO_vdprintf, vdprintf) -#endif +ldbl_weak_alias (_IO_vdprintf, vdprintf) diff --git a/libio/iovsprintf.c b/libio/iovsprintf.c index b26a99b271..7fcd0a156e 100644 --- a/libio/iovsprintf.c +++ b/libio/iovsprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997-2003 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2003, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -29,10 +29,7 @@ #include "strfile.h" int -_IO_vsprintf (string, format, args) - char *string; - const char *format; - _IO_va_list args; +__IO_vsprintf (char *string, const char *format, _IO_va_list args) { _IO_strfile sf; int ret; @@ -47,8 +44,7 @@ _IO_vsprintf (string, format, args) _IO_putc_unlocked ('\0', (_IO_FILE *) &sf._sbf); return ret; } -INTDEF(_IO_vsprintf) +INTDEF2(__IO_vsprintf, _IO_vsprintf) -#ifdef weak_alias -weak_alias (_IO_vsprintf, vsprintf) -#endif +ldbl_strong_alias (__IO_vsprintf, _IO_vsprintf) +ldbl_weak_alias (__IO_vsprintf, vsprintf) diff --git a/libio/iovsscanf.c b/libio/iovsscanf.c index 1a965c2d92..10e4b0a9ac 100644 --- a/libio/iovsscanf.c +++ b/libio/iovsscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997-2003 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2003, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -45,8 +45,5 @@ _IO_vsscanf (string, format, args) ret = INTUSE(_IO_vfscanf) ((_IO_FILE *) &sf._sbf, format, args, NULL); return ret; } - -#ifdef weak_alias -weak_alias (_IO_vsscanf, __vsscanf) -weak_alias (_IO_vsscanf, vsscanf) -#endif +ldbl_weak_alias (_IO_vsscanf, __vsscanf) +ldbl_weak_alias (_IO_vsscanf, vsscanf) diff --git a/libio/iovswscanf.c b/libio/iovswscanf.c index 1bbddd442f..182d8da410 100644 --- a/libio/iovswscanf.c +++ b/libio/iovswscanf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1993, 1997-2000, 2001, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2000, 2001, 2002, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -30,10 +31,7 @@ #include <wchar.h> int -vswscanf (string, format, args) - const wchar_t *string; - const wchar_t *format; - _IO_va_list args; +__vswscanf (const wchar_t *string, const wchar_t *format, _IO_va_list args) { int ret; _IO_strfile sf; @@ -47,4 +45,5 @@ vswscanf (string, format, args) ret = _IO_vfwscanf ((_IO_FILE *) &sf._sbf, format, args, NULL); return ret; } -libc_hidden_def (vswscanf) +ldbl_hidden_def (__vswscanf, vswscanf) +ldbl_strong_alias (__vswscanf, vswscanf) diff --git a/libio/libio.h b/libio/libio.h index 21e70489cf..6f9c418c31 100644 --- a/libio/libio.h +++ b/libio/libio.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1991-1995,1997-2003,2004,2005 Free Software Foundation, Inc. +/* Copyright (C) 1991-1995,1997-2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Per Bothner <bothner@cygnus.com>. @@ -317,13 +317,19 @@ struct _IO_FILE_complete /* Wide character stream stuff. */ struct _IO_codecvt *_codecvt; struct _IO_wide_data *_wide_data; + struct _IO_FILE *_freeres_list; + void *_freeres_buf; + size_t _freeres_size; # else void *__pad1; void *__pad2; + void *__pad3; + void *__pad4; + size_t __pad5; # endif int _mode; /* Make sure we don't get into trouble again. */ - char _unused2[15 * sizeof (int) - 2 * sizeof (void *)]; + char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; #endif }; @@ -472,9 +478,9 @@ extern int _IO_ftrylockfile (_IO_FILE *) __THROW; #endif /* !_IO_MTSAFE_IO */ extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict, - _IO_va_list, int *__restrict) __THROW; + _IO_va_list, int *__restrict); extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict, - _IO_va_list) __THROW; + _IO_va_list); extern _IO_ssize_t _IO_padn (_IO_FILE *, int, _IO_ssize_t) __THROW; extern _IO_size_t _IO_sgetn (_IO_FILE *, void *, _IO_size_t) __THROW; @@ -521,13 +527,17 @@ weak_extern (_IO_stdin_used); # endif extern int _IO_vfwscanf (_IO_FILE * __restrict, const wchar_t * __restrict, - _IO_va_list, int *__restrict) __THROW; + _IO_va_list, int *__restrict); extern int _IO_vfwprintf (_IO_FILE *__restrict, const wchar_t *__restrict, - _IO_va_list) __THROW; + _IO_va_list); extern _IO_ssize_t _IO_wpadn (_IO_FILE *, wint_t, _IO_ssize_t) __THROW; extern void _IO_free_wbackup_area (_IO_FILE *) __THROW; #endif +#ifdef __LDBL_COMPAT +# include <bits/libio-ldbl.h> +#endif + #ifdef __cplusplus } #endif diff --git a/libio/libioP.h b/libio/libioP.h index be3b38a2e4..a2cd4c2202 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -1,4 +1,5 @@ -/* Copyright (C) 1993, 1997-2003, 2004, 2005 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997-2003,2004,2005,2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -35,6 +36,8 @@ /*# include <comthread.h>*/ #endif +#include <math_ldbl_opt.h> + #include "iolibio.h" /* Control of exported symbols. Used in glibc. By default we don't @@ -649,7 +652,7 @@ extern void _IO_wstr_finish (_IO_FILE *, int) __THROW; extern int _IO_vasprintf (char **result_ptr, __const char *format, _IO_va_list args) __THROW; -extern int _IO_vdprintf (int d, __const char *format, _IO_va_list arg) __THROW; +extern int _IO_vdprintf (int d, __const char *format, _IO_va_list arg); extern int _IO_vsnprintf (char *string, _IO_size_t maxlen, __const char *format, _IO_va_list args) __THROW; diff --git a/libio/memstream.c b/libio/memstream.c index 4cc9ab2dfc..742da740ef 100644 --- a/libio/memstream.c +++ b/libio/memstream.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-97,99,2000,2002,2003,2004 Free Software Foundation, Inc. +/* Copyright (C) 1995-97,99,2000,2002-2004,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -106,11 +106,6 @@ _IO_mem_sync (fp) _IO_FILE* fp; { struct _IO_FILE_memstream *mp = (struct _IO_FILE_memstream *) fp; - int res; - - res = _IO_default_sync (fp); - if (res < 0) - return res; if (fp->_IO_write_ptr == fp->_IO_write_end) { @@ -140,9 +135,9 @@ _IO_mem_finish (fp, dummy) { (*mp->bufloc)[fp->_IO_write_ptr - fp->_IO_write_base] = '\0'; *mp->sizeloc = fp->_IO_write_ptr - fp->_IO_write_base; - } - fp->_IO_buf_base = NULL; + fp->_IO_buf_base = NULL; + } - INTUSE(_IO_default_finish) (fp, 0); + _IO_str_finish (fp, 0); } diff --git a/libio/obprintf.c b/libio/obprintf.c index 1167a93d0b..0a50c8e0fc 100644 --- a/libio/obprintf.c +++ b/libio/obprintf.c @@ -1,5 +1,5 @@ /* Print output of stream to given obstack. - Copyright (C) 1996,1997,1999,2000,2001,2002,2003,2004,2005 + Copyright (C) 1996,1997,1999,2000,2001,2002,2003,2004,2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -176,9 +176,7 @@ _IO_obstack_vprintf (struct obstack *obstack, const char *format, va_list args) return result; } -#ifdef weak_alias -weak_alias (_IO_obstack_vprintf, obstack_vprintf) -#endif +ldbl_weak_alias (_IO_obstack_vprintf, obstack_vprintf) int @@ -191,6 +189,4 @@ _IO_obstack_printf (struct obstack *obstack, const char *format, ...) va_end (ap); return result; } -#ifdef weak_alias -weak_alias (_IO_obstack_printf, obstack_printf) -#endif +ldbl_weak_alias (_IO_obstack_printf, obstack_printf) diff --git a/libio/stdio.h b/libio/stdio.h index 3be5728579..80838d2997 100644 --- a/libio/stdio.h +++ b/libio/stdio.h @@ -295,6 +295,11 @@ extern FILE *fmemopen (void *__s, size_t __len, __const char *__modes) __THROW; and the number of characters written on fflush or fclose. */ extern FILE *open_memstream (char **__restrict __bufloc, size_t *__restrict __sizeloc) __THROW; + +/* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces + a wide character string. */ +extern FILE *open_wmemstream (wchar_t **__restrict __bufloc, + size_t *__restrict __sizeloc) __THROW; #endif @@ -838,6 +843,9 @@ extern void funlockfile (FILE *__stream) __THROW; #if __USE_FORTIFY_LEVEL > 0 && !defined __cplusplus # include <bits/stdio2.h> #endif +#ifdef __LDBL_COMPAT +# include <bits/stdio-ldbl.h> +#endif __END_DECLS diff --git a/libio/swprintf.c b/libio/swprintf.c index 298c1e7537..ea0bdfd33c 100644 --- a/libio/swprintf.c +++ b/libio/swprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991,1995,1997,1998,1999,2000,2003 +/* Copyright (C) 1991,1995,1997,1998,1999,2000,2003,2004,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -17,13 +17,14 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libioP.h> #include <stdarg.h> #include <wchar.h> /* Write formatted output into S, according to the format string FORMAT. */ /* VARARGS3 */ int -swprintf (wchar_t *s, size_t n, const wchar_t *format, ...) +__swprintf (wchar_t *s, size_t n, const wchar_t *format, ...) { va_list arg; int done; @@ -34,3 +35,4 @@ swprintf (wchar_t *s, size_t n, const wchar_t *format, ...) return done; } +ldbl_strong_alias (__swprintf, swprintf) diff --git a/libio/swscanf.c b/libio/swscanf.c index c837ad14f6..f93d207416 100644 --- a/libio/swscanf.c +++ b/libio/swscanf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991,1995,1996,1998,1999,2003 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1995, 1996, 1998, 1999, 2003, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,13 +17,14 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libioP.h> #include <stdarg.h> #include <wchar.h> /* Read formatted input from S, according to the format string FORMAT. */ /* VARARGS2 */ int -swscanf (const wchar_t *s, const wchar_t *format, ...) +__swscanf (const wchar_t *s, const wchar_t *format, ...) { va_list arg; int done; @@ -33,3 +35,4 @@ swscanf (const wchar_t *s, const wchar_t *format, ...) return done; } +ldbl_strong_alias (__swscanf, swscanf) diff --git a/libio/tst-fopenloc2.c b/libio/tst-fopenloc2.c new file mode 100644 index 0000000000..5ddd63446b --- /dev/null +++ b/libio/tst-fopenloc2.c @@ -0,0 +1,116 @@ +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <wchar.h> + + +static const struct +{ + const char *enc; + const char *data; + size_t datalen; + const wchar_t *expected; + size_t expectedlen; +} tests[] = + { + { "UCS-4LE", "a\0\0\0b\0\0\0", 8, L"ab", 2 }, + { "UCS-4BE", "\0\0\0a\0\0\0b", 8, L"ab", 2 }, + }; +#define ntests (sizeof (tests) / sizeof (tests[0])) + + +static int do_test (void); +#define TEST_FUNCTION do_test () + +static void prepare (void); +#define PREPARE(argc, argv) prepare (); + +#include "../test-skeleton.c" + + +static int fd; +static char *tmpname; + + +static void +prepare (void) +{ + fd = create_temp_file ("tst-fopenloc2", &tmpname); + if (fd == -1) + { + puts ("cannot open temp file"); + exit (1); + } +} + + +static int +do_test (void) +{ + for (int i = 0; i < ntests; ++i) + { + if (ftruncate (fd, 0) != 0) + { + printf ("ftruncate in round %d failed\n", i + 1); + return 1; + } + + if (TEMP_FAILURE_RETRY (write (fd, tests[i].data, tests[i].datalen)) + != tests[i].datalen) + { + printf ("write in round %d failed\n", i + 1); + return 1; + } + + if (lseek (fd, 0, SEEK_SET) != 0) + { + printf ("lseek in round %d failed\n", i + 1); + return 1; + } + + char *ccs; + if (asprintf (&ccs, "r,ccs=%s", tests[i].enc) == -1) + { + printf ("asprintf in round %d failed\n", i + 1); + return 1; + } + + FILE *fp = fopen (tmpname, ccs); + if (fp == NULL) + { + printf ("fopen in round %d failed\n", i + 1); + return 1; + } + +#define LINELEN 100 + wchar_t line[LINELEN]; + if (fgetws (line, LINELEN, fp) != line) + { + printf ("fgetws in round %d failed\n", i + 1); + return 1; + } + + if (wcslen (line) != tests[i].expectedlen) + { + printf ("round %d: expected length %zu, got length %zu\n", + i + 1, tests[i].expectedlen, wcslen (line)); + return 1; + } + + if (wcscmp (tests[i].expected, line) != 0) + { + printf ("round %d: expected L\"%ls\", got L\"%ls\"\n", + i + 1, tests[i].expected, line); + return 1; + } + + fclose (fp); + + free (ccs); + } + + close (fd); + + return 0; +} diff --git a/libio/tst-memstream1.c b/libio/tst-memstream1.c new file mode 100644 index 0000000000..d18f5cc22a --- /dev/null +++ b/libio/tst-memstream1.c @@ -0,0 +1,89 @@ +#include <mcheck.h> +#include <stdio.h> + + +#ifndef CHAR_T +# define CHAR_T char +# define W(o) o +# define OPEN_MEMSTREAM open_memstream +#endif + +#define S(s) S1 (s) +#define S1(s) #s + + +static void +mcheck_abort (enum mcheck_status ev) +{ + printf ("mecheck failed with status %d\n", (int) ev); + exit (1); +} + + +static int +do_test (void) +{ + mcheck_pedantic (mcheck_abort); + + CHAR_T *buf = (CHAR_T *) 1l; + size_t len = 12345; + FILE *fp = OPEN_MEMSTREAM (&buf, &len); + if (fp == NULL) + { + printf ("%s failed\n", S(OPEN_MEMSTREAM)); + return 1; + } + + if (fflush (fp) != 0) + { + puts ("fflush failed"); + return 1; + } + + if (len != 0) + { + puts ("string after no write not empty"); + return 1; + } + if (buf == (CHAR_T *) 1l) + { + puts ("buf not updated"); + return 1; + } + if (buf[0] != W('\0')) + { + puts ("buf[0] != 0"); + return 1; + } + + buf = (CHAR_T *) 1l; + len = 12345; + if (fclose (fp) != 0) + { + puts ("fclose failed"); + return 1; + } + + if (len != 0) + { + puts ("string after close with no write not empty"); + return 1; + } + if (buf == (CHAR_T *) 1l) + { + puts ("buf not updated"); + return 1; + } + if (buf[0] != W('\0')) + { + puts ("buf[0] != 0"); + return 1; + } + + free (buf); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/libio/tst-memstream2.c b/libio/tst-memstream2.c new file mode 100644 index 0000000000..9619d7725d --- /dev/null +++ b/libio/tst-memstream2.c @@ -0,0 +1,104 @@ +#include <mcheck.h> +#include <stdio.h> + + +#ifndef CHAR_T +# define CHAR_T char +# define W(o) o +# define OPEN_MEMSTREAM open_memstream +#endif + +#define S(s) S1 (s) +#define S1(s) #s + + +static void +mcheck_abort (enum mcheck_status ev) +{ + printf ("mecheck failed with status %d\n", (int) ev); + exit (1); +} + + +static int +do_test (void) +{ + mcheck_pedantic (mcheck_abort); + + CHAR_T *buf = (CHAR_T *) 1l; + size_t len = 12345; + FILE *fp = OPEN_MEMSTREAM (&buf, &len); + if (fp == NULL) + { + printf ("%s failed\n", S(OPEN_MEMSTREAM)); + return 1; + } + + for (int outer = 0; outer < 800; ++outer) + { + for (int inner = 0; inner < 100; ++inner) + if (fputc (W('a') + (outer * 100 + inner) % 26, fp) == EOF) + { + printf ("fputc at %d:%d failed\n", outer, inner); + return 1; + } + + if (fflush (fp) != 0) + { + puts ("fflush failed"); + return 1; + } + + if (len != (outer + 1) * 100) + { + printf ("string in round %d not %d bytest long\n", + outer + 1, (outer + 1) * 100); + return 1; + } + if (buf == (CHAR_T *) 1l) + { + printf ("round %d: buf not updated\n", outer + 1); + return 1; + } + for (int inner = 0; inner < (outer + 1) * 100; ++inner) + if (buf[inner] != W('a') + inner % 26) + { + printf ("round %d: buf[%d] != '%c'\n", outer + 1, inner, + (char) (W('a') + inner % 26)); + return 1; + } + } + + buf = (CHAR_T *) 1l; + len = 12345; + if (fclose (fp) != 0) + { + puts ("fclose failed"); + return 1; + } + + if (len != 800 * 100) + { + puts ("string after close not 80000 bytes long"); + return 1; + } + if (buf == (CHAR_T *) 1l) + { + puts ("buf not updated"); + return 1; + } + for (int inner = 0; inner < 800 * 100; ++inner) + if (buf[inner] != W('a') + inner % 26) + { + printf ("after close: buf[%d] != %c\n", inner, + (char) (W('a') + inner % 26)); + return 1; + } + + free (buf); + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/libio/tst-wmemstream1.c b/libio/tst-wmemstream1.c new file mode 100644 index 0000000000..0c59c1adcb --- /dev/null +++ b/libio/tst-wmemstream1.c @@ -0,0 +1,5 @@ +#define CHAR_T wchar_t +#define W(o) L##o +#define OPEN_MEMSTREAM open_wmemstream + +#include "tst-memstream1.c" diff --git a/libio/tst-wmemstream2.c b/libio/tst-wmemstream2.c new file mode 100644 index 0000000000..f51a1db20c --- /dev/null +++ b/libio/tst-wmemstream2.c @@ -0,0 +1,5 @@ +#define CHAR_T wchar_t +#define W(o) L##o +#define OPEN_MEMSTREAM open_wmemstream + +#include "tst-memstream2.c" diff --git a/libio/vasprintf.c b/libio/vasprintf.c index e32a488438..ac7733006d 100644 --- a/libio/vasprintf.c +++ b/libio/vasprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995,1997,1999-2002,2004 Free Software Foundation, Inc. +/* Copyright (C) 1995,1997,1999-2002,2004,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -87,7 +87,4 @@ _IO_vasprintf (result_ptr, format, args) (*result_ptr)[needed - 1] = '\0'; return ret; } - -#ifdef weak_alias -weak_alias (_IO_vasprintf, vasprintf) -#endif +ldbl_weak_alias (_IO_vasprintf, vasprintf) diff --git a/libio/vscanf.c b/libio/vscanf.c index 477cbaee84..78c30eefdf 100644 --- a/libio/vscanf.c +++ b/libio/vscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997, 2002, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -37,7 +37,4 @@ _IO_vscanf (format, args) { return INTUSE(_IO_vfscanf) (_IO_stdin, format, args, NULL); } - -#ifdef weak_alias -weak_alias (_IO_vscanf, vscanf) -#endif +ldbl_weak_alias (_IO_vscanf, vscanf) diff --git a/libio/vsnprintf.c b/libio/vsnprintf.c index 4250c2d2de..289160e540 100644 --- a/libio/vsnprintf.c +++ b/libio/vsnprintf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1994,1997,1999-2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1994,1997,1999-2003, 2004, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -123,8 +123,5 @@ _IO_vsnprintf (string, maxlen, format, args) *sf.f._sbf._f._IO_write_ptr = '\0'; return ret; } - -#ifdef weak_alias -weak_alias (_IO_vsnprintf, __vsnprintf) -weak_alias (_IO_vsnprintf, vsnprintf) -#endif +ldbl_weak_alias (_IO_vsnprintf, __vsnprintf) +ldbl_weak_alias (_IO_vsnprintf, vsnprintf) diff --git a/libio/vswprintf.c b/libio/vswprintf.c index eda8495241..5bbd20227b 100644 --- a/libio/vswprintf.c +++ b/libio/vswprintf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1994,1997,1999-2002,2004,2005 Free Software Foundation, Inc. +/* Copyright (C) 1994, 1997, 1999-2002, 2004, 2005, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -126,8 +127,5 @@ _IO_vswprintf (string, maxlen, format, args) return ret; } - -#ifdef weak_alias weak_alias (_IO_vswprintf, __vswprintf) -weak_alias (_IO_vswprintf, vswprintf) -#endif +ldbl_weak_alias (_IO_vswprintf, vswprintf) diff --git a/libio/vwprintf.c b/libio/vwprintf.c index 814fdf32bf..bd9a950c7c 100644 --- a/libio/vwprintf.c +++ b/libio/vwprintf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991,1993,1995,1997,1999,2001 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1993, 1995, 1997, 1999, 2001, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -23,9 +25,8 @@ /* Write formatted output to stdout according to the format string FORMAT, using the argument list in ARG. */ int -vwprintf (format, arg) - const wchar_t *format; - __gnuc_va_list arg; +__vwprintf (const wchar_t *format, __gnuc_va_list arg) { return __vfwprintf (stdout, format, arg); } +ldbl_strong_alias (__vwprintf, vwprintf) diff --git a/libio/vwscanf.c b/libio/vwscanf.c index cd7af9ce5b..f6d04e8e87 100644 --- a/libio/vwscanf.c +++ b/libio/vwscanf.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1997, 1999 Free Software Foundation, Inc. +/* Copyright (C) 1993, 1997, 1999, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -29,9 +29,8 @@ #include <wchar.h> int -vwscanf (format, args) - const wchar_t *format; - _IO_va_list args; +__vwscanf (const wchar_t *format, _IO_va_list args) { return _IO_vfwscanf (_IO_stdin, format, args, NULL); } +ldbl_strong_alias (__vwscanf, vwscanf) diff --git a/libio/wfileops.c b/libio/wfileops.c index 5f9faac223..b930aad067 100644 --- a/libio/wfileops.c +++ b/libio/wfileops.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1997-2003,2004 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2003,2004, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Written by Ulrich Drepper <drepper@cygnus.com>. Based on the single byte version by Per Bothner <bothner@cygnus.com>. @@ -69,7 +69,7 @@ _IO_wdo_write (fp, data, to_do) { if (_IO_new_do_write (fp, fp->_IO_write_base, fp->_IO_write_ptr - fp->_IO_write_base) == EOF) - return EOF; + return WEOF; } do diff --git a/libio/wmemstream.c b/libio/wmemstream.c new file mode 100644 index 0000000000..1709f2dd33 --- /dev/null +++ b/libio/wmemstream.c @@ -0,0 +1,149 @@ +/* Copyright (C) 1995-97,99,2000,2002-2004,2006 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include "libioP.h" +#include "strfile.h" +#include <stdio.h> +#include <stdlib.h> + + +struct _IO_FILE_wmemstream +{ + _IO_strfile _sf; + wchar_t **bufloc; + _IO_size_t *sizeloc; +}; + + +static int _IO_wmem_sync (_IO_FILE* fp) __THROW; +static void _IO_wmem_finish (_IO_FILE* fp, int) __THROW; + + +static const struct _IO_jump_t _IO_wmem_jumps = +{ + JUMP_INIT_DUMMY, + JUMP_INIT (finish, _IO_wmem_finish), + JUMP_INIT (overflow, (_IO_overflow_t) _IO_wstr_overflow), + JUMP_INIT (underflow, (_IO_underflow_t) _IO_wstr_underflow), + JUMP_INIT (uflow, (_IO_underflow_t) INTUSE(_IO_wdefault_uflow)), + JUMP_INIT (pbackfail, (_IO_pbackfail_t) _IO_wstr_pbackfail), + JUMP_INIT (xsputn, INTUSE(_IO_wdefault_xsputn)), + JUMP_INIT (xsgetn, INTUSE(_IO_wdefault_xsgetn)), + JUMP_INIT (seekoff, _IO_wstr_seekoff), + JUMP_INIT (seekpos, _IO_default_seekpos), + JUMP_INIT (setbuf, _IO_default_setbuf), + JUMP_INIT (sync, _IO_wmem_sync), + JUMP_INIT (doallocate, INTUSE(_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), + JUMP_INIT (showmanyc, _IO_default_showmanyc), + JUMP_INIT (imbue, _IO_default_imbue) +}; + +/* Open a stream that writes into a malloc'd buffer that is expanded as + necessary. *BUFLOC and *SIZELOC are updated with the buffer's location + and the number of characters written on fflush or fclose. */ +_IO_FILE * +open_wmemstream (bufloc, sizeloc) + wchar_t **bufloc; + _IO_size_t *sizeloc; +{ + struct locked_FILE + { + struct _IO_FILE_wmemstream fp; +#ifdef _IO_MTSAFE_IO + _IO_lock_t lock; +#endif + struct _IO_wide_data wd; + } *new_f; + wchar_t *buf; + + new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE)); + if (new_f == NULL) + return NULL; +#ifdef _IO_MTSAFE_IO + new_f->fp._sf._sbf._f._lock = &new_f->lock; +#endif + + buf = malloc (_IO_BUFSIZ); + if (buf == NULL) + return NULL; + + _IO_no_init (&new_f->fp._sf._sbf._f, 0, 0, &new_f->wd, &_IO_wmem_jumps); + _IO_fwide (&new_f->fp._sf._sbf._f, 1); + _IO_wstr_init_static (&new_f->fp._sf._sbf._f, buf, + _IO_BUFSIZ / sizeof (wchar_t), buf); + new_f->fp._sf._sbf._f._flags &= ~_IO_USER_BUF; + 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.bufloc = bufloc; + new_f->fp.sizeloc = sizeloc; + + return (_IO_FILE *) &new_f->fp._sf._sbf; +} + + +static int +_IO_wmem_sync (fp) + _IO_FILE* fp; +{ + struct _IO_FILE_wmemstream *mp = (struct _IO_FILE_wmemstream *) fp; + + if (fp->_wide_data->_IO_write_ptr == fp->_wide_data->_IO_write_end) + { + _IO_wstr_overflow (fp, '\0'); + --fp->_wide_data->_IO_write_ptr; + } + else + *fp->_wide_data->_IO_write_ptr = '\0'; + + *mp->bufloc = fp->_wide_data->_IO_write_base; + *mp->sizeloc = (fp->_wide_data->_IO_write_ptr + - fp->_wide_data->_IO_write_base); + + return 0; +} + + +static void +_IO_wmem_finish (fp, dummy) + _IO_FILE* fp; + int dummy; +{ + struct _IO_FILE_wmemstream *mp = (struct _IO_FILE_wmemstream *) fp; + + *mp->bufloc = (wchar_t *) realloc (fp->_wide_data->_IO_write_base, + (fp->_wide_data->_IO_write_ptr + - fp->_wide_data->_IO_write_base + 1) + * sizeof (wchar_t)); + if (*mp->bufloc != NULL) + { + size_t len = (fp->_wide_data->_IO_write_ptr + - fp->_wide_data->_IO_write_base); + (*mp->bufloc)[len] = '\0'; + *mp->sizeloc = len; + + fp->_wide_data->_IO_buf_base = NULL; + } + + _IO_wstr_finish (fp, 0); +} diff --git a/libio/wprintf.c b/libio/wprintf.c index f418cf515d..d06451c15a 100644 --- a/libio/wprintf.c +++ b/libio/wprintf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991,1995,1996,1997,1999,2001 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1995, 1996, 1997, 1999, 2001, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -23,7 +25,7 @@ /* Write formatted output to stdout from the format string FORMAT. */ /* VARARGS1 */ int -wprintf (const wchar_t *format, ...) +__wprintf (const wchar_t *format, ...) { va_list arg; int done; @@ -34,3 +36,4 @@ wprintf (const wchar_t *format, ...) return done; } +ldbl_strong_alias (__wprintf, wprintf) diff --git a/libio/wscanf.c b/libio/wscanf.c index f4b8cd1b83..3eba6207c3 100644 --- a/libio/wscanf.c +++ b/libio/wscanf.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1991, 1995, 1996, 1997, 1999 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1995, 1996, 1997, 1999, 2006 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -16,6 +17,7 @@ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include <libioP.h> #include <stdarg.h> #include <stdio.h> #include <wchar.h> @@ -24,7 +26,7 @@ /* Read formatted input from stdin according to the format string FORMAT. */ /* VARARGS1 */ int -wscanf (const wchar_t *format, ...) +__wscanf (const wchar_t *format, ...) { va_list arg; int done; @@ -35,3 +37,4 @@ wscanf (const wchar_t *format, ...) return done; } +ldbl_strong_alias (__wscanf, wscanf) |