1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-08 08:58:00 +00:00
putty-source/miscucs.c
Simon Tatham 7762d71226 New centralised helper function dup_mb_to_wc().
PuTTY's main mb_to_wc() function is all very well for embedding in
fiddly data pipelines, but for the simple job of turning a C string
into a C wide string, really I want something much more like
dupprintf. So here is one.

I've had to put it in a new separate source file miscucs.c rather than
throwing it into misc.c, because misc.c is linked into tools that
don't also include a module providing the internal Unicode API (winucs
or uxucs). The new miscucs.c appears only in Unicode-using tools.
2015-07-27 20:06:02 +01:00

29 lines
745 B
C

/*
* Centralised Unicode-related helper functions, separate from misc.c
* so that they can be omitted from tools that aren't including
* Unicode handling.
*/
#include "putty.h"
#include "misc.h"
wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len)
{
int mult;
for (mult = 1 ;; mult++) {
wchar_t *ret = snewn(mult*len + 2, wchar_t);
int outlen;
outlen = mb_to_wc(codepage, flags, string, len, ret, mult*len + 1);
if (outlen < mult*len+1) {
ret[outlen] = L'\0';
return ret;
}
sfree(ret);
}
}
wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string)
{
return dup_mb_to_wc_c(codepage, flags, string, strlen(string));
}