Convert mbtowc to mbrtowc everywhere #308

pull/312/head
nick black 5 years ago
parent 44f80694a3
commit f3af2b8760
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -483,7 +483,9 @@ int witherworm_demo(struct notcurses* nc){
break; break;
} }
wchar_t wcs; wchar_t wcs;
int eaten = mbtowc(&wcs, &(*s)[idx], MB_CUR_MAX + 1); mbstate_t mbstate;
memset(&mbstate, 0, sizeof(mbstate));
int eaten = mbrtowc(&wcs, &(*s)[idx], MB_CUR_MAX + 1, &mbstate);
if(eaten < 0){ if(eaten < 0){
return -1; return -1;
} }

@ -59,7 +59,7 @@ egcpool_grow(egcpool* pool, size_t len){
} }
// Eat an EGC from the UTF-8 string input. This consists of extracting a // Eat an EGC from the UTF-8 string input. This consists of extracting a
// multibyte via mbtowc, then continuing to extract any which have zero // multibyte via mbrtowc, then continuing to extract any which have zero
// width until hitting another spacing character or a NUL terminator. Writes // width until hitting another spacing character or a NUL terminator. Writes
// the number of columns occupied to '*colcount'. Returns the number of bytes // the number of columns occupied to '*colcount'. Returns the number of bytes
// consumed, not including any NUL terminator. Note that neither the number // consumed, not including any NUL terminator. Note that neither the number
@ -193,9 +193,11 @@ egcpool_check_validity(const egcpool* pool, int offset){
fprintf(stderr, "Bad offset 0x%06x: empty\n", offset); fprintf(stderr, "Bad offset 0x%06x: empty\n", offset);
return false; return false;
} }
mbstate_t mbstate;
memset(&mbstate, 0, sizeof(mbstate));
do{ do{
wchar_t wcs; wchar_t wcs;
int r = mbtowc(&wcs, egc, strlen(egc)); int r = mbrtowc(&wcs, egc, strlen(egc), &mbstate);
if(r < 0){ if(r < 0){
fprintf(stderr, "Invalid UTF8 at offset 0x%06x, len %zu [%s]\n", fprintf(stderr, "Invalid UTF8 at offset 0x%06x, len %zu [%s]\n",
offset, strlen(egc), strerror(errno)); offset, strlen(egc), strerror(errno));

@ -251,8 +251,12 @@ handle_getc(notcurses* nc, int kpress, ncinput* ni){
} }
cpoint[cpointlen] = '\0'; cpoint[cpointlen] = '\0';
wchar_t w; wchar_t w;
mbstate_t mbstate;
memset(&mbstate, 0, sizeof(mbstate));
// FIXME how the hell does this work with 16-bit wchar_t? // FIXME how the hell does this work with 16-bit wchar_t?
if(mbtowc(&w, cpoint, cpointlen) < 0){ size_t r;
if((r = mbrtowc(&w, cpoint, cpointlen, &mbstate)) == (size_t)-1 ||
r == (size_t)-2){
return (wchar_t)-1; return (wchar_t)-1;
} }
return w; return w;

Loading…
Cancel
Save