Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam
2024-07-12 14:01:09 +01:00
3 changed files with 34 additions and 0 deletions

22
utf8.c
View File

@ -449,6 +449,28 @@ utf8_towc(const struct utf8_data *ud, wchar_t *wc)
return (UTF8_DONE);
}
/* Convert wide character to UTF-8 character. */
enum utf8_state
utf8_fromwc(wchar_t wc, struct utf8_data *ud)
{
int size, width;
size = wctomb(ud->data, wc);
if (size < 0) {
log_debug("UTF-8 %d, wctomb() %d", wc, errno);
wctomb(NULL, 0);
return (UTF8_ERROR);
}
if (size == 0)
return (UTF8_ERROR);
ud->size = ud->have = size;
if (utf8_width(ud, &width) == UTF8_DONE) {
ud->width = width;
return (UTF8_DONE);
}
return (UTF8_ERROR);
}
/*
* Open UTF-8 sequence.
*