miscucs.c 745 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Centralised Unicode-related helper functions, separate from misc.c
  3. * so that they can be omitted from tools that aren't including
  4. * Unicode handling.
  5. */
  6. #include "putty.h"
  7. #include "misc.h"
  8. wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len)
  9. {
  10. int mult;
  11. for (mult = 1 ;; mult++) {
  12. wchar_t *ret = snewn(mult*len + 2, wchar_t);
  13. int outlen;
  14. outlen = mb_to_wc(codepage, flags, string, len, ret, mult*len + 1);
  15. if (outlen < mult*len+1) {
  16. ret[outlen] = L'\0';
  17. return ret;
  18. }
  19. sfree(ret);
  20. }
  21. }
  22. wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string)
  23. {
  24. return dup_mb_to_wc_c(codepage, flags, string, strlen(string));
  25. }