dup_wc_to_mb.c 788 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * dup_wc_to_mb: memory-allocating wrapper on wc_to_mb.
  3. *
  4. * Also dup_wc_to_mb_c: same but you already know the length of the
  5. * wide string, and you get told the length of the returned string.
  6. * (But it's still NUL-terminated, for convenience.).
  7. */
  8. #include <wchar.h>
  9. #include "putty.h"
  10. #include "misc.h"
  11. char *dup_wc_to_mb_c(int codepage, const wchar_t *string,
  12. size_t inlen, const char *defchr, size_t *outlen_p)
  13. {
  14. strbuf *sb = strbuf_new();
  15. put_wc_to_mb(sb, codepage, string, inlen, defchr);
  16. if (outlen_p)
  17. *outlen_p = sb->len;
  18. return strbuf_to_str(sb);
  19. }
  20. char *dup_wc_to_mb(int codepage, const wchar_t *string,
  21. const char *defchr)
  22. {
  23. return dup_wc_to_mb_c(codepage, string, wcslen(string), defchr, NULL);
  24. }