[CRT] Make _controlfp_s portable

This commit is contained in:
Timo Kreuzer 2023-08-06 09:50:39 +03:00
parent a17dd3a7a9
commit 994d5e0ad1
4 changed files with 32 additions and 35 deletions

View File

@ -0,0 +1,31 @@
/*
* PROJECT: ReactOS CRT library
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Implementation of _controlfp_s (adapted from wine msvcrt/math.c)
* COPYRIGHT: Copyright 2000 Jon Griffiths
* Copyright 2010 Piotr Caban
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
*/
#include <precomp.h>
#include <float.h>
#ifdef _M_ARM
#define INVALID_MASK ~(_MCW_EM | _MCW_RC | _MCW_DN)
#else
#define INVALID_MASK ~(_MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC | _MCW_DN)
#endif
int CDECL _controlfp_s(unsigned int* cur, unsigned int newval, unsigned int mask)
{
unsigned int val;
if (!MSVCRT_CHECK_PMT((newval & mask & INVALID_MASK) == 0))
{
if (cur) *cur = _controlfp(0, 0); /* retrieve it anyway */
return EINVAL;
}
val = _controlfp(newval, mask);
if (cur) *cur = val;
return 0;
}

View File

@ -68,16 +68,3 @@ unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
return flags;
}
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
{
unsigned int val;
if (!MSVCRT_CHECK_PMT( !(newval & mask & ~(_MCW_EM | _MCW_RC | _MCW_DN)) ))
{
if (cur) *cur = _controlfp(0, 0); /* retrieve it anyway */
return EINVAL;
}
val = _controlfp(newval, mask);
if (cur) *cur = val;
return 0;
}

View File

@ -6,6 +6,7 @@ list(APPEND LIBCNTPR_FLOAT_SOURCE
list(APPEND CRT_FLOAT_SOURCE
${LIBCNTPR_FLOAT_SOURCE}
float/chgsign.c
float/_controlfp_s.c
float/copysign.c
float/fpclass.c
float/fpecode.c

View File

@ -113,25 +113,3 @@ unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
return flags;
}
/*********************************************************************
* _controlfp_s (MSVCRT.@)
*/
int CDECL _controlfp_s(unsigned int *cur, unsigned int newval, unsigned int mask)
{
#ifdef __i386__
unsigned int val;
if (!MSVCRT_CHECK_PMT( !(newval & mask & ~(_MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC | _MCW_DN))))
{
if (cur) *cur = _controlfp( 0, 0 ); /* retrieve it anyway */
return EINVAL;
}
val = _controlfp( newval, mask );
if (cur) *cur = val;
return 0;
#else
FIXME(":Not Implemented!\n");
return 0;
#endif
}