'\" te .\" Copyright (c) 2007, Sun Microsystems Inc. All Rights Reserved. .TH u8_validate 9F "18 Sep 2007" "SunOS 5.11" "Kernel Functions for Drivers" .SH NAME u8_validate \- validate UTF-8 characters and calculate the byte length .SH SYNOPSIS .LP .nf #include #include #include \fBint\fR u8_validate(\fBchar *\fR\fIu8str\fR, \fBsize_t\fR \fIn\fR, \fBchar **\fR\fIlist\fR, \fBint\fR \fIflag\fR, \fBint *\fR\fIerrno\fR); .fi .SH INTERFACE LEVEL .sp .LP Solaris DDI specific (Solaris DDI) .SH PARAMETERS .sp .ne 2 .mk .na \fB\fIu8str\fR\fR .ad .RS 9n .rt The UTF-8 string to be validated. .RE .sp .ne 2 .mk .na \fB\fIn\fR\fR .ad .RS 9n .rt The maximum number of bytes in \fIu8str\fR that can be examined and validated. .RE .sp .ne 2 .mk .na \fB\fIlist\fR\fR .ad .RS 9n .rt A list of null-terminated character strings in UTF-8 that must be additionally checked against as invalid characters. The last string in \fIlist\fR must be null to indicate there is no further string. .RE .sp .ne 2 .mk .na \fB\fIflag\fR\fR .ad .RS 9n .rt Possible validation options constructed by a bitwise-inclusive-OR of the following values: .sp .ne 2 .mk .na \fB\fBU8_VALIDATE_ENTIRE\fR\fR .ad .sp .6 .RS 4n By default, \fBu8_validate()\fR looks at the first character or up to \fIn\fR bytes, whichever is smaller in terms of the number of bytes to be consumed, and returns with the result. .sp When this option is used, \fBu8_validate()\fR will check up to \fIn\fR bytes from \fIu8str\fR and possibly more than a character before returning the result. .RE .sp .ne 2 .mk .na \fB\fBU8_VALIDATE_CHECK_ADDITIONAL\fR\fR .ad .sp .6 .RS 4n By default, \fBu8_validate()\fR does not use list supplied. .sp When this option is supplied with a list of character strings, \fBu8_validate()\fR additionally validates \fIu8str\fR against the character strings supplied with \fIlist\fR and returns EBADF in \fIerrno\fR if \fIu8str\fR has any one of the character strings in \fIlist\fR. .RE .sp .ne 2 .mk .na \fB\fBU8_VALIDATE_UCS2_RANGE\fR\fR .ad .sp .6 .RS 4n By default, \fBu8_validate()\fR uses the entire Unicode coding space of U+0000 to U+10FFFF. .sp When this option is specified, the valid Unicode coding space is smaller to U+0000 to U+FFFF. .RE .RE .sp .ne 2 .mk .na \fB\fIerrno\fR\fR .ad .RS 9n .rt An error occurred during validation. The following values are supported: .sp .ne 2 .mk .na \fB\fBEBADF\fR\fR .ad .RS 10n .rt Validation failed because list-specified characters were found in the string pointed to by \fIu8str\fR. .RE .sp .ne 2 .mk .na \fB\fBEILSEQ\fR\fR .ad .RS 10n .rt Validation failed because an illegal byte was found in the string pointed to by \fIu8str\fR. .RE .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 10n .rt Validation failed because an incomplete byte was found in the string pointed to by \fIu8str\fR. .RE .sp .ne 2 .mk .na \fB\fBERANGE\fR\fR .ad .RS 10n .rt Validation failed because character bytes were encountered that are outside the range of the Unicode coding space. .RE .RE .SH DESCRIPTION .sp .LP The \fBu8_validate()\fR function validates \fIu8str\fR in UTF-8 and determines the number of bytes constituting the character(s) pointed to by \fIu8str\fR. .SH RETURN VALUES .sp .LP If \fIu8str\fR is a null pointer, \fBu8_validate()\fR returns 0. Otherwise, \fBu8_validate()\fR returns either the number of bytes that constitute the characters if the next \fIn\fR or fewer bytes form valid characters, or -1 if there is an validation failure, in which case it may set \fIerrno\fR to indicate the error. .SH EXAMPLES .LP \fBExample 1 \fRDetermine the length of the first UTF-8 character. .sp .in +2 .nf #include #include #include char u8[MAXPATHLEN]; int errno; \&. \&. \&. len = u8_validate(u8, 4, (char **)NULL, 0, &errno); if (len == -1) { switch (errno) { case EILSEQ: case EINVAL: return (MYFS4_ERR_INVAL); case EBADF: return (MYFS4_ERR_BADNAME); case ERANGE: return (MYFS4_ERR_BADCHAR); default: return (-10); } } .fi .in -2 .LP \fBExample 2 \fRCheck if there are any invalid characters in the entire string. .sp .in +2 .nf #include #include #include char u8[MAXPATHLEN]; int n; int errno; \&. \&. \&. n = strlen(u8); len = u8_validate(u8, n, (char **)NULL, U8_VALIDATE_ENTIRE, &errno); if (len == -1) { switch (errno) { case EILSEQ: case EINVAL: return (MYFS4_ERR_INVAL); case EBADF: return (MYFS4_ERR_BADNAME); case ERANGE: return (MYFS4_ERR_BADCHAR); default: return (-10); } } .fi .in -2 .LP \fBExample 3 \fRCheck if there is any invalid character, including prohibited characters, in the entire string. .sp .in +2 .nf #include #include #include char u8[MAXPATHLEN]; int n; int errno; char *prohibited[4] = { ".", "..", "\e\e", NULL }; \&. \&. \&. n = strlen(u8); len = u8_validate(u8, n, prohibited, (U8_VALIDATE_ENTIRE|U8_VALIDATE_CHECK_ADDITIONAL), &errno); if (len == -1) { switch (errno) { case EILSEQ: case EINVAL: return (MYFS4_ERR_INVAL); case EBADF: return (MYFS4_ERR_BADNAME); case ERANGE: return (MYFS4_ERR_BADCHAR); default: return (-10); } } .fi .in -2 .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted .TE .SH SEE ALSO .sp .LP \fBu8_strcmp\fR(3C), \fBu8_textprep_str\fR(3C), \fBu8_validate\fR(3C), \fBattributes\fR(5), \fBu8_strcmp\fR(9F), \fBu8_textprep_str\fR(9F), \fBuconv_u16tou32\fR(9F) .sp .LP The Unicode Standard (http://www.unicode.org)