locale.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <assert.h>
  7. #include <locale.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. extern "C" {
  11. static char default_decimal_point[] = ".";
  12. static char default_thousands_sep[] = ",";
  13. static char default_grouping[] = "\x03\x03";
  14. static char default_empty_string[] = "";
  15. static char default_empty_value = 127;
  16. static struct lconv default_locale = {
  17. default_decimal_point,
  18. default_thousands_sep,
  19. default_grouping,
  20. default_empty_string,
  21. default_empty_string,
  22. default_empty_string,
  23. default_empty_string,
  24. default_empty_string,
  25. default_empty_string,
  26. default_empty_string,
  27. default_empty_value,
  28. default_empty_value,
  29. default_empty_value,
  30. default_empty_value,
  31. default_empty_value,
  32. default_empty_value,
  33. default_empty_value,
  34. default_empty_value,
  35. default_empty_value,
  36. default_empty_value,
  37. default_empty_value,
  38. default_empty_value,
  39. default_empty_value,
  40. default_empty_value
  41. };
  42. char* setlocale(int, char const* locale)
  43. {
  44. static char c_locale_string[2];
  45. memcpy(c_locale_string, "C", 2);
  46. // If we get a null pointer, return the current locale as per POSIX spec.
  47. if (locale == nullptr)
  48. return c_locale_string;
  49. if (strcmp(locale, "POSIX") == 0 || strcmp(locale, "C") == 0 || strcmp(locale, "") == 0)
  50. return c_locale_string;
  51. return nullptr;
  52. }
  53. struct lconv* localeconv()
  54. {
  55. return &default_locale;
  56. }
  57. }