xref: /reactos/sdk/lib/ucrt/locale/localeconv.cpp (revision b09b5584)
1 /***
2 *lconv.c - Contains the localeconv function
3 *
4 *       Copyright (c) Microsoft Corporation. All rights reserved.
5 *
6 *Purpose:
7 *       Contains the localeconv() function.
8 *
9 *******************************************************************************/
10 #include <corecrt_internal.h>
11 #include <limits.h>
12 #include <locale.h>
13 
14 
15 
16 /* pointer to original static to avoid freeing */
17 extern "C" { char    __acrt_lconv_static_decimal  []{"."}; }
18 extern "C" { char    __acrt_lconv_static_null     []{""}; }
19 extern "C" { wchar_t __acrt_lconv_static_W_decimal[]{L"."}; }
20 extern "C" { wchar_t __acrt_lconv_static_W_null   []{L""}; }
21 
22 /* lconv settings for "C" locale */
23 extern "C" { struct lconv __acrt_lconv_c
24 {
25     __acrt_lconv_static_decimal,   // decimal_point
26     __acrt_lconv_static_null,      // thousands_sep
27     __acrt_lconv_static_null,      // grouping
28     __acrt_lconv_static_null,      // int_curr_symbol
29     __acrt_lconv_static_null,      // currency_symbol
30     __acrt_lconv_static_null,      // mon_decimal_point
31     __acrt_lconv_static_null,      // mon_thousands_sep
32     __acrt_lconv_static_null,      // mon_grouping
33     __acrt_lconv_static_null,      // positive_sign
34     __acrt_lconv_static_null,      // negative_sign
35     CHAR_MAX,                      // int_frac_digits
36     CHAR_MAX,                      // frac_digits
37     CHAR_MAX,                      // p_cs_precedes
38     CHAR_MAX,                      // p_sep_by_space
39     CHAR_MAX,                      // n_cs_precedes
40     CHAR_MAX,                      // n_sep_by_space
41     CHAR_MAX,                      // p_sign_posn
42     CHAR_MAX,                      // n_sign_posn
43     __acrt_lconv_static_W_decimal, // _W_decimal_point
44     __acrt_lconv_static_W_null,    // _W_thousands_sep
45     __acrt_lconv_static_W_null,    // _W_int_curr_symbol
46     __acrt_lconv_static_W_null,    // _W_currency_symbol
47     __acrt_lconv_static_W_null,    // _W_mon_decimal_point
48     __acrt_lconv_static_W_null,    // _W_mon_thousands_sep
49     __acrt_lconv_static_W_null,    // _W_positive_sign
50     __acrt_lconv_static_W_null,    // _W_negative_sign
51 }; }
52 
53 
54 /* pointer to current lconv structure */
55 
56 extern "C" { struct lconv* __acrt_lconv{&__acrt_lconv_c}; }
57 
58 /***
59 *struct lconv *localeconv(void) - Return the numeric formatting convention
60 *
61 *Purpose:
62 *       The localeconv() routine returns the numeric formatting conventions
63 *       for the current locale setting.  [ANSI]
64 *
65 *Entry:
66 *       void
67 *
68 *Exit:
69 *       struct lconv * = pointer to struct indicating current numeric
70 *                        formatting conventions.
71 *
72 *Exceptions:
73 *
74 *******************************************************************************/
75 
76 extern "C" lconv* __cdecl localeconv()
77 {
78     // Note that we don't need _LocaleUpdate in this function.  The main reason
79     // being, that this is a leaf function in locale usage terms.
80     __acrt_ptd* const ptd = __acrt_getptd();
81     __crt_locale_data* locale_info = ptd->_locale_info;
82 
83     __acrt_update_locale_info(ptd, &locale_info);
84 
85     return locale_info->lconv;
86 }
87