mirror of
git://source.winehq.org/git/wine.git
synced 2024-09-06 05:50:37 +00:00
msvcrt: Implement ecvt_s.
This commit is contained in:
parent
a967d985c2
commit
1ade6c2bc8
|
@ -583,7 +583,7 @@
|
|||
@ cdecl _dup2(long long) msvcrt._dup2
|
||||
@ cdecl _dupenv_s(ptr ptr str) msvcrt._dupenv_s
|
||||
@ cdecl _ecvt(double long ptr ptr) msvcrt._ecvt
|
||||
@ stub _ecvt_s
|
||||
@ cdecl _ecvt_s(str long double long ptr ptr) msvcrt._ecvt_s
|
||||
@ cdecl _encoded_null() msvcr90._encoded_null
|
||||
@ cdecl _endthread() msvcrt._endthread
|
||||
@ cdecl _endthreadex(long) msvcrt._endthreadex
|
||||
|
|
|
@ -423,7 +423,7 @@
|
|||
@ cdecl _dup2(long long) msvcrt._dup2
|
||||
@ cdecl _dupenv_s(ptr ptr str) msvcrt._dupenv_s
|
||||
@ cdecl _ecvt(double long ptr ptr) msvcrt._ecvt
|
||||
@ stub _ecvt_s
|
||||
@ cdecl _ecvt_s(str long double long ptr ptr) msvcrt._ecvt_s
|
||||
@ cdecl _encode_pointer(ptr) msvcr90._encode_pointer
|
||||
@ cdecl _encoded_null() msvcr90._encoded_null
|
||||
@ cdecl _endthread() msvcrt._endthread
|
||||
|
|
|
@ -415,7 +415,7 @@
|
|||
@ cdecl _dup2(long long) msvcrt._dup2
|
||||
@ cdecl _dupenv_s(ptr ptr str) msvcrt._dupenv_s
|
||||
@ cdecl _ecvt(double long ptr ptr) msvcrt._ecvt
|
||||
@ stub _ecvt_s
|
||||
@ cdecl _ecvt_s(str long double long ptr ptr) msvcrt._ecvt_s
|
||||
@ cdecl _encode_pointer(ptr) MSVCR90_encode_pointer
|
||||
@ cdecl _encoded_null()
|
||||
@ cdecl _endthread() msvcrt._endthread
|
||||
|
|
|
@ -1104,6 +1104,72 @@ char * CDECL _ecvt( double number, int ndigits, int *decpt, int *sign )
|
|||
return data->efcvt_buffer;
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* _ecvt_s (MSVCRT.@)
|
||||
*/
|
||||
int CDECL _ecvt_s( char *buffer, MSVCRT_size_t length, double number, int ndigits, int *decpt, int *sign )
|
||||
{
|
||||
int prec, len;
|
||||
char *result;
|
||||
const char infret[] = "1#INF";
|
||||
|
||||
if(!MSVCRT_CHECK_PMT(buffer != NULL) || !MSVCRT_CHECK_PMT(decpt != NULL) || !MSVCRT_CHECK_PMT(sign != NULL))
|
||||
{
|
||||
*MSVCRT__errno() = MSVCRT_EINVAL;
|
||||
return MSVCRT_EINVAL;
|
||||
}
|
||||
if(!MSVCRT_CHECK_PMT(length > 2) || !MSVCRT_CHECK_PMT(ndigits < (int)length - 1))
|
||||
{
|
||||
*MSVCRT__errno() = MSVCRT_ERANGE;
|
||||
return MSVCRT_ERANGE;
|
||||
}
|
||||
|
||||
/* special case - inf */
|
||||
if(number == HUGE_VAL || number == -HUGE_VAL)
|
||||
{
|
||||
memset(buffer, '0', ndigits);
|
||||
memcpy(buffer, infret, min(ndigits, sizeof(infret) - 1 ) );
|
||||
buffer[ndigits] = '\0';
|
||||
(*decpt) = 1;
|
||||
if(number == -HUGE_VAL)
|
||||
(*sign) = 1;
|
||||
else
|
||||
(*sign) = 0;
|
||||
return 0;
|
||||
}
|
||||
result = (char*)MSVCRT_malloc(max(ndigits + 7, 7));
|
||||
|
||||
if( number < 0) {
|
||||
*sign = TRUE;
|
||||
number = -number;
|
||||
} else
|
||||
*sign = FALSE;
|
||||
/* handle cases with zero ndigits or less */
|
||||
prec = ndigits;
|
||||
if( prec < 1) prec = 2;
|
||||
len = snprintf(result, 80, "%.*le", prec - 1, number);
|
||||
/* take the decimal "point away */
|
||||
if( prec != 1)
|
||||
memmove( result + 1, result + 2, len - 1 );
|
||||
/* take the exponential "e" out */
|
||||
result[ prec] = '\0';
|
||||
/* read the exponent */
|
||||
sscanf( result + prec + 1, "%d", decpt);
|
||||
(*decpt)++;
|
||||
/* adjust for some border cases */
|
||||
if( result[0] == '0')/* value is zero */
|
||||
*decpt = 0;
|
||||
/* handle cases with zero ndigits or less */
|
||||
if( ndigits < 1){
|
||||
if( result[ 0] >= '5')
|
||||
(*decpt)++;
|
||||
result[ 0] = '\0';
|
||||
}
|
||||
memcpy( buffer, result, max(ndigits + 1, 1) );
|
||||
MSVCRT_free( result );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
* _fcvt (MSVCRT.@)
|
||||
*/
|
||||
|
|
|
@ -378,7 +378,7 @@
|
|||
@ cdecl _dup (long) MSVCRT__dup
|
||||
@ cdecl _dup2 (long long) MSVCRT__dup2
|
||||
@ cdecl _ecvt(double long ptr ptr)
|
||||
# stub _ecvt_s
|
||||
@ cdecl _ecvt_s(str long double long ptr ptr)
|
||||
@ cdecl _endthread ()
|
||||
@ cdecl _endthreadex(long)
|
||||
@ extern _environ MSVCRT__environ
|
||||
|
|
Loading…
Reference in a new issue