diff options
author | Curtis McEnroe | 2018-08-07 16:24:14 -0400 |
---|---|---|
committer | Curtis McEnroe | 2018-08-07 16:24:14 -0400 |
commit | a6ede6f91f41ca20d02454de3bd33329d35fbbd1 (patch) | |
tree | a3d9eab30cd4ae9cca359f6649a6e2cc4a0b3299 /ui.c | |
parent | 2fe8b4e61448fed717a06300a8a7c74604a81ca0 (diff) |
Factor out allocating conversion between wcs and mbs
Diffstat (limited to 'ui.c')
-rw-r--r-- | ui.c | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/ui.c b/ui.c index 2e028ff..62c3b3c 100644 --- a/ui.c +++ b/ui.c @@ -267,11 +267,10 @@ void uiTopic(const wchar_t *topic) { } void uiTopicStr(const char *topic) { - size_t len = strlen(topic); - wchar_t wcs[1 + len]; - len = mbstowcs(wcs, topic, 1 + len); - if (len == (size_t)-1) err(EX_DATAERR, "mbstowcs"); + wchar_t *wcs = ambstowcs(topic); + if (!wcs) err(EX_DATAERR, "ambstowcs"); uiTopic(wcs); + free(wcs); } void uiLog(const wchar_t *line) { @@ -350,16 +349,10 @@ static void delete(void) { static void enter(void) { if (line.end == line.buf) return; *line.end = L'\0'; - - const wchar_t *src = line.buf; - size_t len = wcsrtombs(NULL, &src, 0, NULL); - if (len == (size_t)-1) err(EX_DATAERR, "wcsrtombs"); - - char buf[1 + len]; - len = wcsrtombs(buf, &src, sizeof(buf), NULL); - if (len == (size_t)-1) err(EX_DATAERR, "wcsrtombs"); - - input(buf); + char *str = awcstombs(line.buf); + if (!str) err(EX_DATAERR, "awcstombs"); + input(str); + free(str); line.ptr = line.buf; line.end = line.buf; } |