This is the first in my msvcrt-A?? series of patches, consolidating all the changes made over the last while to msvcrt, incorporating changes as requested on the wine-devel mailing list and making sure that everything still applies cleanly to the CVS tree. License: LGPL Changelog: * dlls/msvcrt/file.c, dlls/msvcrt/Makefile.in, dlls/msvcrt/vfprintf.c: Jaco Greeff <jaco@puxedo.org> - Moved the vfprintf and vfwprintf functions to vfprintf.c to allow for the start of a full vfprintf implementation --[ inline patch ]-- diff -aurN msvcrt-A00/dlls/msvcrt/file.c msvcrt-A01/dlls/msvcrt/file.c --- msvcrt-A00/dlls/msvcrt/file.c 2002-10-25 03:12:01.000000000 +0000 +++ msvcrt-A01/dlls/msvcrt/file.c 2002-11-02 19:45:39.000000000 +0000 @@ -2190,59 +2190,6 @@ } /********************************************************************* - * vfprintf (MSVCRT.@) - */ -int MSVCRT_vfprintf(MSVCRT_FILE* file, const char *format, va_list valist) -{ - char buf[2048], *mem = buf; - int written, resize = sizeof(buf), retval; - /* There are two conventions for vsnprintf failing: - * Return -1 if we truncated, or - * Return the number of bytes that would have been written - * The code below handles both cases - */ - while ((written = vsnprintf(mem, resize, format, valist)) == -1 || - written > resize) - { - resize = (written == -1 ? resize * 2 : written + 1); - if (mem != buf) - MSVCRT_free (mem); - if (!(mem = (char *)MSVCRT_malloc(resize))) - return MSVCRT_EOF; - } - retval = MSVCRT_fwrite(mem, sizeof(*mem), written, file); - if (mem != buf) - MSVCRT_free (mem); - return retval; -} - -/********************************************************************* - * vfwprintf (MSVCRT.@) - * FIXME: - * Is final char included in written (then resize is too big) or not - * (then we must test for equality too)? - */ -int MSVCRT_vfwprintf(MSVCRT_FILE* file, const WCHAR *format, va_list valist) -{ - WCHAR buf[2048], *mem = buf; - int written, resize = sizeof(buf) / sizeof(WCHAR), retval; - /* See vfprintf comments */ - while ((written = _vsnwprintf(mem, resize, format, valist)) == -1 || - written > resize) - { - resize = (written == -1 ? resize * 2 : written + sizeof(WCHAR)); - if (mem != buf) - MSVCRT_free (mem); - if (!(mem = (WCHAR *)MSVCRT_malloc(resize*sizeof(*mem)))) - return MSVCRT_EOF; - } - retval = MSVCRT_fwrite(mem, sizeof(*mem), written, file); - if (mem != buf) - MSVCRT_free (mem); - return retval; -} - -/********************************************************************* * vprintf (MSVCRT.@) */ int MSVCRT_vprintf(const char *format, va_list valist) diff -aurN msvcrt-A00/dlls/msvcrt/Makefile.in msvcrt-A01/dlls/msvcrt/Makefile.in --- msvcrt-A00/dlls/msvcrt/Makefile.in 2002-10-30 23:49:03.000000000 +0000 +++ msvcrt-A01/dlls/msvcrt/Makefile.in 2002-11-02 19:39:22.000000000 +0000 @@ -35,6 +35,7 @@ string.c \ thread.c \ time.c \ + vfprintf.c \ wcs.c SUBDIRS = tests diff -aurN msvcrt-A00/dlls/msvcrt/vfprintf.c msvcrt-A01/dlls/msvcrt/vfprintf.c --- msvcrt-A00/dlls/msvcrt/vfprintf.c 1970-01-01 00:00:00.000000000 +0000 +++ msvcrt-A01/dlls/msvcrt/vfprintf.c 2002-11-03 11:23:45.000000000 +0000 @@ -0,0 +1,97 @@ +/* vfprintf, vfwprintf for MSVCRT and internal helper functions thereof + * + * Copyright 2002 Jaco Greeff + * + * This 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. + * + * This 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 this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "config.h" +#include "wine/port.h" + +#include <stdarg.h> +#include <string.h> +#include <stdio.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#include "winbase.h" +#include "winnls.h" +#include "wine/unicode.h" +#include "msvcrt/stdio.h" +#include "msvcrt/stdlib.h" +#include "msvcrt/string.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(msvcrt); + +/********************************************************************* + * vfprintf (MSVCRT.@) + * + * FIXME: We don't handle the Microsoft format flag extentions + * %C and %S at all + */ +int MSVCRT_vfprintf(MSVCRT_FILE *fFile, const char *szFormat, va_list vaList) +{ + char buf[2048], *mem = buf; + int written, resize = sizeof(buf), retval; + + /* There are two conventions for vsnprintf failing: + * Return -1 if we truncated, or + * Return the number of bytes that would have been written + * The code below handles both cases + */ + while ((written = vsnprintf(mem, resize, szFormat, vaList)) == -1 || + written > resize) + { + resize = (written == -1 ? resize * 2 : written + 1); + if (mem != buf) + MSVCRT_free (mem); + if (!(mem = (char *)MSVCRT_malloc(resize))) + return MSVCRT_EOF; + } + retval = MSVCRT_fwrite(mem, sizeof(*mem), written, fFile); + if (mem != buf) + MSVCRT_free (mem); + return retval; +} + +/********************************************************************* + * vfwprintf (MSVCRT.@) + * + * FIXME: We don't handle the Microsoft format flag extentions + * %C and %S at all + */ +int MSVCRT_vfwprintf(MSVCRT_FILE *fFile, const WCHAR *szFormat, va_list vaList) +{ + WCHAR buf[2048], *mem = buf; + int written, resize = sizeof(buf) / sizeof(WCHAR), retval; + + /* See vfprintf comments */ + while ((written = _vsnwprintf(mem, resize, szFormat, vaList)) == -1 || + written > resize) + { + resize = (written == -1 ? resize * 2 : written + sizeof(WCHAR)); + if (mem != buf) + MSVCRT_free (mem); + if (!(mem = (WCHAR *)MSVCRT_malloc(resize*sizeof(*mem)))) + return MSVCRT_EOF; + } + retval = MSVCRT_fwrite(mem, sizeof(*mem), written, fFile); + if (mem != buf) + MSVCRT_free (mem); + return retval; +}