From 573a3e8e5e20b467f547cc712016b11f63fc126e Mon Sep 17 00:00:00 2001 From: tjr Date: Tue, 3 Sep 2002 01:09:47 +0000 Subject: Set errno to EILSEQ when invalid multibyte sequences are detected (XSI extension to 1003.1-2001). --- lib/libc/locale/mblen.c | 5 ++++- lib/libc/locale/mbtowc.c | 5 ++++- lib/libc/locale/wctomb.c | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/libc/locale/mblen.c b/lib/libc/locale/mblen.c index 2544ba8..b5b92d1 100644 --- a/lib/libc/locale/mblen.c +++ b/lib/libc/locale/mblen.c @@ -37,6 +37,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -51,7 +52,9 @@ mblen(s, n) if (s == 0 || *s == 0) return (0); /* No support for state dependent encodings. */ - if (sgetrune(s, n, &e) == _INVALID_RUNE) + if (sgetrune(s, n, &e) == _INVALID_RUNE) { + errno = EILSEQ; return (s - e); + } return (e - s); } diff --git a/lib/libc/locale/mbtowc.c b/lib/libc/locale/mbtowc.c index 67771a0..67b7b38 100644 --- a/lib/libc/locale/mbtowc.c +++ b/lib/libc/locale/mbtowc.c @@ -37,6 +37,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -53,8 +54,10 @@ mbtowc(pwc, s, n) if (s == 0 || *s == 0) return (0); /* No support for state dependent encodings. */ - if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) + if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) { + errno = EILSEQ; return (s - e); + } if (pwc) *pwc = r; return (e - s); diff --git a/lib/libc/locale/wctomb.c b/lib/libc/locale/wctomb.c index ca5ed8d..2a225f4 100644 --- a/lib/libc/locale/wctomb.c +++ b/lib/libc/locale/wctomb.c @@ -37,6 +37,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include #include @@ -58,5 +59,9 @@ wctomb(s, wchar) } sputrune(wchar, s, MB_CUR_MAX, &e); - return (e ? e - s : -1); + if (e == NULL) { + errno = EILSEQ; + return (-1); + } + return (e - s); } -- cgit v1.1