1 #include <float.h>
2 #include <errno.h>
3 #include <windows.h>
4 #include <msvcrt.h>
5
6 static errno_t __cdecl _stub(
7 unsigned int *currentControl,
8 unsigned int newControl,
9 unsigned int mask
10 );
11
12 errno_t __cdecl (*__MINGW_IMP_SYMBOL(_controlfp_s))(unsigned int *, unsigned int, unsigned int) = _stub;
13
_controlfp_s(unsigned int * currentControl,unsigned int newControl,unsigned int mask)14 errno_t __cdecl _controlfp_s(
15 unsigned int *currentControl,
16 unsigned int newControl,
17 unsigned int mask
18 ){
19 return __MINGW_IMP_SYMBOL(_controlfp_s)(currentControl,newControl,mask);
20 }
21
22 static const unsigned int allflags = _MCW_DN | _MCW_EM | _MCW_IC | _MCW_RC | _MCW_PC;
_int_controlfp_s(unsigned int * currentControl,unsigned int newControl,unsigned int mask)23 static errno_t __cdecl _int_controlfp_s(
24 unsigned int *currentControl,
25 unsigned int newControl,
26 unsigned int mask
27 ){
28 unsigned int cont;
29 if(!(newControl & mask & ~allflags)){
30 if (currentControl) *currentControl = _controlfp( 0, 0 );
31 return EINVAL;
32 }
33 cont = _controlfp( newControl, mask );
34 if(currentControl) *currentControl = cont;
35 return 0;
36 }
37
_stub(unsigned int * currentControl,unsigned int newControl,unsigned int mask)38 static errno_t __cdecl _stub (
39 unsigned int *currentControl,
40 unsigned int newControl,
41 unsigned int mask
42 )
43 {
44 errno_t __cdecl (*f)(unsigned int *, unsigned int, unsigned int) = __MINGW_IMP_SYMBOL(_controlfp_s);
45
46 if (f == _stub)
47 {
48 f = (errno_t __cdecl (*)(unsigned int *, unsigned int, unsigned int))
49 GetProcAddress (__mingw_get_msvcrt_handle (), "_controlfp_s");
50 if (!f)
51 f = _int_controlfp_s;
52 __MINGW_IMP_SYMBOL(_controlfp_s) = f;
53 }
54 return (*f)(currentControl, newControl, mask);
55 }
56
57