Set errno to EILSEQ when invalid multibyte sequences are detected
(XSI extension to 1003.1-2001).
This commit is contained in:
parent
f10248e26b
commit
f0c6c306f9
@ -37,6 +37,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <rune.h>
|
||||
@ -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);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <rune.h>
|
||||
@ -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);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stddef.h>
|
||||
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user