[CRT][MSVCRT] Import _gcvt and _gcvt_s from wine and export _gcvt_s on Vista+

Fixes a crash in msvcrt_winetest string
This commit is contained in:
Timo Kreuzer 2023-09-10 19:00:54 +03:00
parent a3d22bba1a
commit 86f98baaf8
2 changed files with 68 additions and 27 deletions

View file

@ -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)

View file

@ -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 (p > buf && p[-1] == '.')
memmove (p - 1, p, strlen (p) + 1);
return buf;
if (ndigit < 0) {
*_errno() = ERANGE;
return NULL;
}
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;
}