https://git.reactos.org/?p=reactos.git;a=commitdiff;h=86f98baaf8874e78543624...
commit 86f98baaf8874e785436241859f1c20dd677f7b9 Author: Timo Kreuzer timo.kreuzer@reactos.org AuthorDate: Sun Sep 10 19:00:54 2023 +0300 Commit: Timo Kreuzer timo.kreuzer@reactos.org CommitDate: Fri Nov 10 19:19:22 2023 +0200
[CRT][MSVCRT] Import _gcvt and _gcvt_s from wine and export _gcvt_s on Vista+
Fixes a crash in msvcrt_winetest string --- dll/win32/msvcrt/msvcrt.spec | 2 +- sdk/lib/crt/stdlib/gcvt.c | 93 +++++++++++++++++++++++++++++++------------- 2 files changed, 68 insertions(+), 27 deletions(-)
diff --git a/dll/win32/msvcrt/msvcrt.spec b/dll/win32/msvcrt/msvcrt.spec index 9f2c5a55eb6..6a7b5372c51 100644 --- a/dll/win32/msvcrt/msvcrt.spec +++ b/dll/win32/msvcrt/msvcrt.spec @@ -549,7 +549,7 @@ @ stub -version=0x600+ _fwscanf_l @ stub -version=0x600+ _fwscanf_s_l @ cdecl _gcvt(double long str) -@ stub -version=0x600+ _gcvt_s +@ cdecl -version=0x600+ _gcvt_s(ptr ptr double long) @ cdecl -version=0x600+ _get_doserrno(ptr) @ stub -version=0x600+ _get_environ @ cdecl -version=0x600+ _get_errno(ptr) diff --git a/sdk/lib/crt/stdlib/gcvt.c b/sdk/lib/crt/stdlib/gcvt.c index 644478fafbb..56fbce83fca 100644 --- a/sdk/lib/crt/stdlib/gcvt.c +++ b/sdk/lib/crt/stdlib/gcvt.c @@ -1,32 +1,73 @@ -/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */ +/* + * msvcrt.dll math functions + * + * Copyright 2003 Alexandre Julliard julliard@winehq.org + * Copyright 2010 Piotr Caban piotr@codeweavers.com + * + * 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * + */ + #include <precomp.h>
-/* - * @implemented +/*********************************************************************** + * _gcvt (MSVCRT.@) */ -char * -_gcvt (double value, int ndigits, char *buf) +char* CDECL _gcvt(double number, int ndigit, char* buff) { - char *p = buf; - - sprintf (buf, "%-#.*g", ndigits, value); - - /* It seems they expect us to return .XXXX instead of 0.XXXX */ - if (*p == '-') - p++; - if (*p == '0' && p[1] == '.') - memmove (p, p + 1, strlen (p + 1) + 1); - - /* They want Xe-YY, not X.e-YY, and XXXX instead of XXXX. */ - p = strchr (buf, 'e'); - if (!p) - { - p = buf + strlen (buf); - /* They don't want trailing zeroes. */ - while (p[-1] == '0' && p > buf + 2) - *--p = '\0'; + if (!buff) { + *_errno() = EINVAL; + return NULL; + } + + if (ndigit < 0) { + *_errno() = ERANGE; + return NULL; } - if (p > buf && p[-1] == '.') - memmove (p - 1, p, strlen (p) + 1); - return buf; + + sprintf(buff, "%.*g", ndigit, number); + return buff; +} + +/*********************************************************************** + * _gcvt_s (MSVCRT.@) + */ +int CDECL _gcvt_s(char* buff, size_t size, double number, int digits) +{ + int len; + + if (!buff) { + *_errno() = EINVAL; + return EINVAL; + } + + if (digits < 0 || digits >= size) { + if (size) + buff[0] = '\0'; + + *_errno() = ERANGE; + return ERANGE; + } + + len = _scprintf("%.*g", digits, number); + if (len > size) { + buff[0] = '\0'; + *_errno() = ERANGE; + return ERANGE; + } + + sprintf(buff, "%.*g", digits, number); + return 0; }