Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.1 KiB

  1. /***
  2. *wsetlocal.c - Contains the setlocale function (wchar_t version)
  3. *
  4. * Copyright (c) 1993-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Contains the _wsetlocale() function.
  8. *
  9. *Revision History:
  10. * 10-29-93 CFW Module created.
  11. * 01-03-94 CFW Fix for NULL locale string.
  12. * 02-07-94 CFW POSIXify.
  13. * 04-15-94 GJF Made definition off outwlocale conditional on
  14. * DLL_FOR_WIN32S.
  15. * 07-26-94 CFW Fix for bug #14663.
  16. * 01-10-95 CFW Debug CRT allocs.
  17. * 01-06-99 GJF Changes for 64-bit size_t.
  18. * 05-13-99 PML Remove Win32s
  19. *
  20. *******************************************************************************/
  21. #ifndef _POSIX_
  22. #include <wchar.h>
  23. #include <stdlib.h>
  24. #include <setlocal.h>
  25. #include <locale.h>
  26. #include <dbgint.h>
  27. wchar_t * __cdecl _wsetlocale (
  28. int _category,
  29. const wchar_t *_wlocale
  30. )
  31. {
  32. size_t size;
  33. char *inlocale = NULL;
  34. char *outlocale;
  35. static wchar_t *outwlocale = NULL;
  36. /* convert WCS string into ASCII string */
  37. if (_wlocale)
  38. {
  39. size = wcslen(_wlocale) + 1;
  40. if (NULL == (inlocale = (char *)_malloc_crt(size * sizeof(char))))
  41. return NULL;
  42. if (-1 == wcstombs(inlocale, _wlocale, size))
  43. {
  44. _free_crt (inlocale);
  45. return NULL;
  46. }
  47. }
  48. /* set the locale and get ASCII return string */
  49. outlocale = setlocale(_category, inlocale);
  50. _free_crt (inlocale);
  51. if (NULL == outlocale)
  52. return NULL;
  53. /* get space for WCS return value */
  54. _free_crt(outwlocale);
  55. if (-1 == (size = mbstowcs(NULL, outlocale, 0)))
  56. return NULL;
  57. size++;
  58. if (NULL == (outwlocale = (wchar_t *)_malloc_crt(size * sizeof(wchar_t))))
  59. return NULL;
  60. /* convert return value to WCS */
  61. if (-1 == mbstowcs(outwlocale, outlocale, size))
  62. {
  63. _free_crt(outwlocale);
  64. return NULL;
  65. }
  66. return outwlocale;
  67. }
  68. #endif /* _POSIX_ */