localeconv.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Query locale dependent information for formatting numbers.
  2. Copyright (C) 2012-2023 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. #include <config.h>
  14. /* Specification. */
  15. #include <locale.h>
  16. #if HAVE_STRUCT_LCONV_DECIMAL_POINT
  17. /* Override for platforms where 'struct lconv' lacks the int_p_*, int_n_*
  18. members. */
  19. struct lconv *
  20. localeconv (void)
  21. {
  22. static struct lconv result;
  23. # undef lconv
  24. # undef localeconv
  25. struct lconv *sys_result = localeconv ();
  26. result.decimal_point = sys_result->decimal_point;
  27. result.thousands_sep = sys_result->thousands_sep;
  28. result.grouping = sys_result->grouping;
  29. result.mon_decimal_point = sys_result->mon_decimal_point;
  30. result.mon_thousands_sep = sys_result->mon_thousands_sep;
  31. result.mon_grouping = sys_result->mon_grouping;
  32. result.positive_sign = sys_result->positive_sign;
  33. result.negative_sign = sys_result->negative_sign;
  34. result.currency_symbol = sys_result->currency_symbol;
  35. result.frac_digits = sys_result->frac_digits;
  36. result.p_cs_precedes = sys_result->p_cs_precedes;
  37. result.p_sign_posn = sys_result->p_sign_posn;
  38. result.p_sep_by_space = sys_result->p_sep_by_space;
  39. result.n_cs_precedes = sys_result->n_cs_precedes;
  40. result.n_sign_posn = sys_result->n_sign_posn;
  41. result.n_sep_by_space = sys_result->n_sep_by_space;
  42. result.int_curr_symbol = sys_result->int_curr_symbol;
  43. result.int_frac_digits = sys_result->int_frac_digits;
  44. result.int_p_cs_precedes = sys_result->p_cs_precedes;
  45. result.int_p_sign_posn = sys_result->p_sign_posn;
  46. result.int_p_sep_by_space = sys_result->p_sep_by_space;
  47. result.int_n_cs_precedes = sys_result->n_cs_precedes;
  48. result.int_n_sign_posn = sys_result->n_sign_posn;
  49. result.int_n_sep_by_space = sys_result->n_sep_by_space;
  50. return &result;
  51. }
  52. #else
  53. /* Override for platforms where 'struct lconv' is a dummy. */
  54. # include <limits.h>
  55. struct lconv *
  56. localeconv (void)
  57. {
  58. static /*const*/ struct lconv result =
  59. {
  60. /* decimal_point */ ".",
  61. /* thousands_sep */ "",
  62. /* grouping */ "",
  63. /* mon_decimal_point */ "",
  64. /* mon_thousands_sep */ "",
  65. /* mon_grouping */ "",
  66. /* positive_sign */ "",
  67. /* negative_sign */ "",
  68. /* currency_symbol */ "",
  69. /* frac_digits */ CHAR_MAX,
  70. /* p_cs_precedes */ CHAR_MAX,
  71. /* p_sign_posn */ CHAR_MAX,
  72. /* p_sep_by_space */ CHAR_MAX,
  73. /* n_cs_precedes */ CHAR_MAX,
  74. /* n_sign_posn */ CHAR_MAX,
  75. /* n_sep_by_space */ CHAR_MAX,
  76. /* int_curr_symbol */ "",
  77. /* int_frac_digits */ CHAR_MAX,
  78. /* int_p_cs_precedes */ CHAR_MAX,
  79. /* int_p_sign_posn */ CHAR_MAX,
  80. /* int_p_sep_by_space */ CHAR_MAX,
  81. /* int_n_cs_precedes */ CHAR_MAX,
  82. /* int_n_sign_posn */ CHAR_MAX,
  83. /* int_n_sep_by_space */ CHAR_MAX
  84. };
  85. return &result;
  86. }
  87. #endif