locale.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <locale.h>
  2. #include <limits.h>
  3. #include <string.h>
  4. static struct lconv Clocale = {
  5. ".", /* decimal_point */
  6. "", /* thousands_sep */
  7. "", /* grouping */
  8. "", /* int_curr_symbol */
  9. "", /* currency_symbol */
  10. "", /* mon_decimal_point */
  11. "", /* mon_thousands_sep */
  12. "", /* mon_grouping */
  13. "", /* positive_sign */
  14. "", /* negative_sign */
  15. CHAR_MAX, /* int_frac_digits */
  16. CHAR_MAX, /* frac_digits */
  17. CHAR_MAX, /* p_cs_precedes */
  18. CHAR_MAX, /* p_sep_by_space */
  19. CHAR_MAX, /* n_cs_precedes */
  20. CHAR_MAX, /* n_sep_by_space */
  21. CHAR_MAX, /* p_sign_posn */
  22. CHAR_MAX, /* n_sign_posn */
  23. };
  24. static char *localename[2] = {"C", ""};
  25. static short catlocale[6] = {0, 0, 0, 0, 0, 0};
  26. /* indices into localename for categories LC_ALL, LC_COLLATE, etc. */
  27. #define ASIZE(a) (sizeof(a)/sizeof(a[0]))
  28. char *
  29. setlocale(int category, const char *locale)
  30. {
  31. int c, i;
  32. if(category < 0 || category >= ASIZE(catlocale))
  33. return 0;
  34. if(!locale)
  35. return localename[catlocale[category]];
  36. for(c=0; c<ASIZE(localename); c++)
  37. if(strcmp(locale, localename[c]) == 0)
  38. break;
  39. if(c >= ASIZE(localename))
  40. return 0;
  41. catlocale[category] = c;
  42. if(category == LC_ALL)
  43. for(i=0; i<ASIZE(catlocale); i++)
  44. catlocale[i] = c;
  45. return localename[c];
  46. }
  47. struct lconv *
  48. localeconv(void)
  49. {
  50. /* BUG: posix says look at environment variables
  51. * to set locale "", but we just make it the same
  52. * as C, always.
  53. */
  54. return &Clocale;
  55. }