X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=opt%2Fbasecodecs%2F_PDCLIB_ascii.c;h=a705a7a75b43da5b18e429b681601b0ad7d144dc;hb=4fe88a1c445105a96d08b808831d6fc7480a211d;hp=2036eb382f58ff5d83b7a805d847cb02038cfce9;hpb=7886c839945ca476d45e5ef0228cae1c138c5a43;p=pdclib.old diff --git a/opt/basecodecs/_PDCLIB_ascii.c b/opt/basecodecs/_PDCLIB_ascii.c index 2036eb3..a705a7a 100644 --- a/opt/basecodecs/_PDCLIB_ascii.c +++ b/opt/basecodecs/_PDCLIB_ascii.c @@ -18,12 +18,15 @@ static bool asciitoc32( { while(*p_outsz && *p_insz) { unsigned char c = **p_inbuf; - if(c > 128) + if(c > 127) return false; - **p_outbuf = c; + + if(p_outbuf) { + **p_outbuf = c; + (*p_outbuf)++; + } (*p_inbuf)++; - (*p_outbuf)++; (*p_insz)--; (*p_outsz)--; } @@ -40,17 +43,26 @@ static bool c32toascii( { while(*p_outsz && *p_insz) { char32_t c = **p_inbuf; - if(c > 128) + if(c > 127) return false; - **p_outbuf = c; + + if(p_outbuf) { + **p_outbuf = c; + (*p_outbuf)++; + } (*p_inbuf)++; - (*p_outbuf)++; (*p_insz)--; (*p_outsz)--; } return true; } + +_PDCLIB_charcodec _PDCLIB_ascii_codec = { + .__mbstoc32s = asciitoc32, + .__c32stombs = c32toascii, +}; + #endif #ifdef TEST