Copyright (c) 2007, Sun Microsystems Inc. All Rights Reserved.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
#include <sys/types.h> #include <sys/errno.h> #include <sys/sunddi.h> int u8_validate(char *u8str, size_t n, char **list, int flag, int *errno);
The UTF-8 string to be validated.
The maximum number of bytes in u8str that can be examined and validated.
A list of null-terminated character strings in UTF-8 that must be additionally checked against as invalid characters. The last string in list must be null to indicate there is no further string.
Possible validation options constructed by a bitwise-inclusive-OR of the following values: U8_VALIDATE_ENTIRE
By default, u8_validate() looks at the first character or up to n bytes, whichever is smaller in terms of the number of bytes to be consumed, and returns with the result. When this option is used, u8_validate() will check up to n bytes from u8str and possibly more than a character before returning the result.
By default, u8_validate() does not use list supplied. When this option is supplied with a list of character strings, u8_validate() additionally validates u8str against the character strings supplied with list and returns EBADF in errno if u8str has any one of the character strings in list.
By default, u8_validate() uses the entire Unicode coding space of U+0000 to U+10FFFF. When this option is specified, the valid Unicode coding space is smaller to U+0000 to U+FFFF.
An error occurred during validation. The following values are supported: EBADF
Validation failed because list-specified characters were found in the string pointed to by u8str.
Validation failed because an illegal byte was found in the string pointed to by u8str.
Validation failed because an incomplete byte was found in the string pointed to by u8str.
Validation failed because character bytes were encountered that are outside the range of the Unicode coding space.
#include <sys/types.h> #include <sys/errno.h> #include <sys/sunddi.h> 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); } }
Example 2 Check if there are any invalid characters in the entire string.
#include <sys/types.h> #include <sys/errno.h> #include <sys/sunddi.h> 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); } }
Example 3 Check if there is any invalid character, including prohibited characters, in the entire string.
#include <sys/types.h> #include <sys/errno.h> #include <sys/sunddi.h> 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); } }
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Committed |
The Unicode Standard (http://www.unicode.org)