- if (endptr != NULL) {
-#if 1 /* Fast, assume 1:1 WC:MBS mapping. */
- *endptr = (wchar_t *)nptr + (end - buf);
- (void)clen;
- (void)p;
-#else /* Slow, conservative approach. */
- state = initial;
- *endptr = (wchar_t *)nptr;
- p = buf;
- while (p < end &&
- (clen = mbrlen(p, end - p, &state)) > 0) {
- p += clen;
- (*endptr)++;
+ first = nptr;
+ mbs = initial;
+ while (*nptr && (len = wcrtomb_l(mb, *nptr, &mbs, ctype)) != (size_t)-1) {
+ mb[len] = 0;
+ if (_simple_sappend(b, mb) < 0) { /* no memory */
+ _simple_sfree(b);
+ return (0.0);