1
0

locale.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. locale.c
  9. Abstract:
  10. This module implements locale functionality for the C library.
  11. Author:
  12. Evan Green 22-Jul-2013
  13. Environment:
  14. User Mode C Library
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include "libcp.h"
  20. #include <assert.h>
  21. #include <limits.h>
  22. #include <locale.h>
  23. //
  24. // ---------------------------------------------------------------- Definitions
  25. //
  26. //
  27. // ------------------------------------------------------ Data Type Definitions
  28. //
  29. //
  30. // ----------------------------------------------- Internal Function Prototypes
  31. //
  32. //
  33. // -------------------------------------------------------------------- Globals
  34. //
  35. //
  36. // Store the current locale information, which is initialized to the "C"
  37. // locale.
  38. //
  39. struct lconv ClLocaleInformation = {
  40. "",
  41. ".",
  42. CHAR_MAX,
  43. "",
  44. "",
  45. CHAR_MAX,
  46. CHAR_MAX,
  47. CHAR_MAX,
  48. CHAR_MAX,
  49. CHAR_MAX,
  50. CHAR_MAX,
  51. CHAR_MAX,
  52. "",
  53. "",
  54. "",
  55. "",
  56. CHAR_MAX,
  57. CHAR_MAX,
  58. CHAR_MAX,
  59. "",
  60. CHAR_MAX,
  61. CHAR_MAX,
  62. CHAR_MAX,
  63. ""
  64. };
  65. //
  66. // ------------------------------------------------------------------ Functions
  67. //
  68. LIBC_API
  69. struct lconv *
  70. localeconv (
  71. void
  72. )
  73. /*++
  74. Routine Description:
  75. This routine returns a pointer to a structure containing the numeric and
  76. monetary customs of the current locale. String members of the structure
  77. may point to "" to indicate that the value is not available in the current
  78. locale or is of zero length. Character members are non-negative numbers,
  79. any of which can be CHAR_MAX to indicate that the value is not available
  80. in the current locale.
  81. Arguments:
  82. None.
  83. Return Value:
  84. Returns a pointer to the filled in structure. The caller must not attempt
  85. to modify or free the returned structure. The structure returned or
  86. storage areas pointed to by the structure may be overwritten or invalidated
  87. by subsequent calls to setlocale or uselocale which affect the categories
  88. LC_ALL, LC_MONETARY, or LC_NUMERIC.
  89. --*/
  90. {
  91. return &ClLocaleInformation;
  92. }
  93. LIBC_API
  94. char *
  95. setlocale (
  96. int Category,
  97. const char *Locale
  98. )
  99. /*++
  100. Routine Description:
  101. This routine sets or returns the appropriate piece of the program's
  102. locale.
  103. Arguments:
  104. Category - Supplies the category of the locale to set. See LC_* definitions.
  105. Locale - Supplies an optional pointer to a string containing the locale to
  106. set. If NULL is supplied, then the current locale will be returned and
  107. left unchanged.
  108. Return Value:
  109. Returns a pointer to a string containing the name of the original locale
  110. for the specified category. This string must not be modified, and may be
  111. overwritten by subsequent calls to this routine.
  112. NULL on failure.
  113. --*/
  114. {
  115. //
  116. // At some point, consider implementing some support for locales.
  117. //
  118. if (Locale != NULL) {
  119. if ((strcmp(Locale, "C") != 0) &&
  120. (strcmp(Locale, "POSIX") != 0) &&
  121. (strcmp(Locale, "") != 0)) {
  122. return NULL;
  123. }
  124. }
  125. return "C";
  126. }
  127. //
  128. // --------------------------------------------------------- Internal Functions
  129. //