diff options
author | Ulf Lamping <ulf.lamping@web.de> | 2006-08-13 12:12:06 +0000 |
---|---|---|
committer | Ulf Lamping <ulf.lamping@web.de> | 2006-08-13 12:12:06 +0000 |
commit | f7f96d52ddf8e85821dfdf9b24ff9d3891debb50 (patch) | |
tree | ac59ddfe97bcec2e845a4cd8d6675738d147289a /dumpcap.c | |
parent | f42021ee231df6198f334d13554528e92b2977c4 (diff) |
another place missing a call to utf_16to8(), the about box was showing "Windows XP S", where it should be "Windows XP Service Pack 2"
dumpcap uses this too, so I had to duplicate utf_16to8 there :-(
svn path=/trunk/; revision=18891
Diffstat (limited to 'dumpcap.c')
-rw-r--r-- | dumpcap.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -624,3 +624,46 @@ signal_pipe_check_running(void) const char *netsnmp_get_version(void) { return ""; } + + +/* Convert from UTF-16 to UTF-8. */ +/* XXX - copied from epan/strutil.c */ +#define INITIAL_FMTBUF_SIZE 128 + +gchar * utf_16to8(const wchar_t *utf16str) { + static gchar *utf8buf[3]; + static int utf8buf_len[3]; + static int idx; + + if (utf16str == NULL) + return NULL; + + idx = (idx + 1) % 3; + + /* + * Allocate the buffer if it's not already allocated. + */ + if (utf8buf[idx] == NULL) { + utf8buf_len[idx] = INITIAL_FMTBUF_SIZE; + utf8buf[idx] = g_malloc(utf8buf_len[idx]); + } + + while (WideCharToMultiByte(CP_UTF8, 0, utf16str, -1, + NULL, 0, NULL, NULL) >= utf8buf_len[idx]) { + /* + * Double the buffer's size if it's not big enough. + * The size of the buffer starts at 128, so doubling its size + * adds at least another 128 bytes, which is more than enough + * for one more character plus a terminating '\0'. + */ + utf8buf_len[idx] *= 2; + utf8buf[idx] = g_realloc(utf8buf[idx], utf8buf_len[idx]); + } + + if (WideCharToMultiByte(CP_UTF8, 0, utf16str, -1, + utf8buf[idx], utf8buf_len[idx], NULL, NULL) == 0) + return NULL; + + return utf8buf[idx]; +} + |