Sync with trunk r63502.
[reactos.git] / lib / sdk / crt / string / winesup.c
1
2 #include "precomp.h"
3 #include "winesup.h"
4
5 #ifdef _LIBCNT_
6
7 static struct lconv _LIBCNT_lconv =
8 {
9 ".", // char* decimal_point;
10 ",", // char* thousands_sep;
11 " ", // char* grouping;
12 "$", // char* int_curr_symbol;
13 "$", // char* currency_symbol;
14 ".", // char* mon_decimal_point;
15 "?", // char* mon_thousands_sep;
16 "/", // char* mon_grouping;
17 "+", // char* positive_sign;
18 "-", // char* negative_sign;
19 4, // char int_frac_digits;
20 4, // char frac_digits;
21 4, // char p_cs_precedes;
22 1, // char p_sep_by_space;
23 0, // char n_cs_precedes;
24 1, // char n_sep_by_space;
25 1, // char p_sign_posn;
26 1, // char n_sign_posn;
27 };
28
29 threadlocinfo _LIBCNT_locinfo =
30 {
31 2, // LONG refcount;
32 0, // CP_ACP, // unsigned int lc_codepage;
33 0, // unsigned int lc_collate_cp;
34 {0}, // unsigned long lc_handle[6];
35 {{0}}, // LC_ID lc_id[6];
36
37 // struct {
38 // char *locale;
39 // wchar_t *wlocale;
40 // int *refcount;
41 // int *wrefcount;
42 // } lc_category[6];
43 {{0}},
44
45 0, // int lc_clike;
46 2, // int mb_cur_max;
47 0, // int *lconv_intl_refcount;
48 0, // int *lconv_num_refcount;
49 0, // int *lconv_mon_refcount;
50 &_LIBCNT_lconv, // struct MSVCRT_lconv *lconv;
51 0, // int *ctype1_refcount;
52 0, // unsigned short *ctype1;
53 0, // const unsigned short *pctype;
54 0, // unsigned char *pclmap;
55 0, // unsigned char *pcumap;
56 0, // struct __lc_time_data *lc_time_curr;
57 };
58
59 #define get_locinfo() (&_LIBCNT_locinfo)
60
61 #endif
62
63 #define _SET_NUMBER_(type) *va_arg((*ap), type*) = negative ? -cur : cur
64
65 void
66 __declspec(noinline)
67 _internal_handle_float(
68 int negative,
69 int exp,
70 int suppress,
71 ULONGLONG d,
72 int l_or_L_prefix,
73 va_list *ap)
74 {
75 long double cur = 1, expcnt = 10;
76 unsigned fpcontrol;
77 BOOL negexp;
78
79 fpcontrol = _control87(0, 0);
80 _control87(_EM_DENORMAL|_EM_INVALID|_EM_ZERODIVIDE
81 |_EM_OVERFLOW|_EM_UNDERFLOW|_EM_INEXACT, 0xffffffff);
82
83 negexp = (exp < 0);
84 if(negexp)
85 exp = -exp;
86 /* update 'cur' with this exponent. */
87 while(exp) {
88 if(exp & 1)
89 cur *= expcnt;
90 exp /= 2;
91 expcnt = expcnt*expcnt;
92 }
93 cur = (negexp ? d/cur : d*cur);
94
95 _control87(fpcontrol, 0xffffffff);
96
97 if (!suppress) {
98 if (l_or_L_prefix) _SET_NUMBER_(double);
99 else _SET_NUMBER_(float);
100 }
101 }
102 #undef _SET_NUMBER_