9103 opengroup acknowledgement should be properly formatted in man pages
[unleashed.git] / usr / src / man / man3c / u8_validate.3c
blobf8700785010fe0b7ae90b23f10c4ba5d69f18476
1 '\" te
2 .\" Copyright (c) 2007, Sun Microsystems Inc. All Rights Reserved.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH U8_VALIDATE 3C "Sep 18, 2007"
7 .SH NAME
8 u8_validate \- validate UTF-8 characters and calculate the byte length
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/u8_textprep.h>
14 \fBint\fR u8_validate(\fBchar *\fR\fIu8str\fR, \fBsize_t\fR \fIn\fR, \fBchar **\fR\fIlist\fR, \fBint\fR \fIflag\fR,
15      \fBint *\fR\fIerrnum\fR);
16 .fi
18 .SH PARAMETERS
19 .sp
20 .ne 2
21 .na
22 \fB\fIu8str\fR\fR
23 .ad
24 .RS 10n
25 The UTF-8 string to be validated.
26 .RE
28 .sp
29 .ne 2
30 .na
31 \fB\fIn\fR\fR
32 .ad
33 .RS 10n
34 The maximum number of bytes in \fIu8str\fR that can be examined and validated.
35 .RE
37 .sp
38 .ne 2
39 .na
40 \fB\fIlist\fR\fR
41 .ad
42 .RS 10n
43 A list of null-terminated character strings in UTF-8 that must be additionally
44 checked against as invalid characters. The last string in \fIlist\fR must be
45 null to indicate there is no further string.
46 .RE
48 .sp
49 .ne 2
50 .na
51 \fB\fIflag\fR\fR
52 .ad
53 .RS 10n
54 Possible validation options constructed by a bitwise-inclusive-OR of the
55 following values:
56 .sp
57 .ne 2
58 .na
59 \fB\fBU8_VALIDATE_ENTIRE\fR\fR
60 .ad
61 .sp .6
62 .RS 4n
63 By default, \fBu8_validate()\fR looks at the first character or up to \fIn\fR
64 bytes, whichever is smaller in terms of the number of bytes to be consumed, and
65 returns with the result.
66 .sp
67 When this option is used, \fBu8_validate()\fR will check up to \fIn\fR bytes
68 from \fIu8str\fR and possibly more than a character before returning the
69 result.
70 .RE
72 .sp
73 .ne 2
74 .na
75 \fB\fBU8_VALIDATE_CHECK_ADDITIONAL\fR\fR
76 .ad
77 .sp .6
78 .RS 4n
79 By default, \fBu8_validate()\fR does not use list supplied.
80 .sp
81 When this option is supplied with a list of character strings,
82 \fBu8_validate()\fR additionally validates \fIu8str\fR against the character
83 strings supplied with \fIlist\fR and returns EBADF in \fIerrnum\fR if
84 \fIu8str\fR has any one of the character strings in \fIlist\fR.
85 .RE
87 .sp
88 .ne 2
89 .na
90 \fB\fBU8_VALIDATE_UCS2_RANGE\fR\fR
91 .ad
92 .sp .6
93 .RS 4n
94 By default, \fBu8_validate()\fR uses the entire Unicode coding space of U+0000
95 to U+10FFFF.
96 .sp
97 When this option is specified, the valid Unicode coding space is smaller to
98 U+0000 to U+FFFF.
99 .RE
104 .ne 2
106 \fB\fIerrnum\fR\fR
108 .RS 10n
109 An error occurred during validation.  The following values are supported:
111 .ne 2
113 \fB\fBEBADF\fR\fR
115 .RS 10n
116 Validation failed because list-specified characters were found in the string
117 pointed to by \fIu8str\fR.
121 .ne 2
123 \fB\fBEILSEQ\fR\fR
125 .RS 10n
126 Validation failed because an illegal byte was found in the string pointed to by
127 \fIu8str\fR.
131 .ne 2
133 \fB\fBEINVAL\fR\fR
135 .RS 10n
136 Validation failed because an incomplete byte was found in the string pointed to
137 by  \fIu8str\fR.
141 .ne 2
143 \fB\fBERANGE\fR\fR
145 .RS 10n
146 Validation failed because character bytes were encountered that are outside the
147 range of the Unicode coding space.
152 .SH DESCRIPTION
155 The \fBu8_validate()\fR function validates \fIu8str\fR in UTF-8 and determines
156 the number of bytes constituting the character(s) pointed to by \fIu8str\fR.
157 .SH RETURN VALUES
160 If \fIu8str\fR is a null pointer, \fBu8_validate()\fR returns 0. Otherwise,
161 \fBu8_validate()\fR returns either the number of bytes that constitute the
162 characters if the next \fIn\fR or fewer bytes form valid characters, or -1 if
163 there is an validation failure, in which case it may set \fIerrnum\fR to
164 indicate the error.
165 .SH EXAMPLES
167 \fBExample 1 \fRDetermine the length of the first UTF-8 character.
169 .in +2
171 #include <sys/u8_textprep.h>
173 char u8[MAXPATHLEN];
174 int errnum;
178 len = u8_validate(u8, 4, (char **)NULL, 0, &errnum);
179 if (len == -1) {
180     switch (errnum) {
181         case EILSEQ:
182         case EINVAL:
183             return (MYFS4_ERR_INVAL);
184         case EBADF:
185             return (MYFS4_ERR_BADNAME);
186         case ERANGE:
187             return (MYFS4_ERR_BADCHAR);
188         default:
189             return (-10);
190     }
193 .in -2
196 \fBExample 2 \fRCheck if there are any invalid characters in the entire string.
198 .in +2
200 #include <sys/u8_textprep.h>
202 char u8[MAXPATHLEN];
203 int n;
204 int errnum;
208 n = strlen(u8);
209 len = u8_validate(u8, n, (char **)NULL, U8_VALIDATE_ENTIRE, &errnum);
210 if (len == -1) {
211     switch (errnum) {
212         case EILSEQ:
213         case EINVAL:
214             return (MYFS4_ERR_INVAL);
215         case EBADF:
216             return (MYFS4_ERR_BADNAME);
217         case ERANGE:
218             return (MYFS4_ERR_BADCHAR);
219         default:
220             return (-10);
221     }
224 .in -2
227 \fBExample 3 \fRCheck if there is any invalid character, including prohibited
228 characters, in the entire string.
230 .in +2
232 #include <sys/u8_textprep.h>
234 char u8[MAXPATHLEN];
235 int n;
236 int errnum;
237 char *prohibited[4] = {
238     ".", "..", "\e\e", NULL
243 n = strlen(u8);
244 len = u8_validate(u8, n, prohibited,
245     (U8_VALIDATE_ENTIRE|U8_VALIDATE_CHECK_ADDITIONAL), &errnum);
246 if (len == -1) {
247     switch (errnum) {
248         case EILSEQ:
249         case EINVAL:
250             return (MYFS4_ERR_INVAL);
251         case EBADF:
252             return (MYFS4_ERR_BADNAME);
253         case ERANGE:
254             return (MYFS4_ERR_BADCHAR);
255         default:
256             return (-10);
257     }
260 .in -2
262 .SH ATTRIBUTES
265 See \fBattributes\fR(5) for descriptions of the following attributes:
270 box;
271 c | c
272 l | l .
273 ATTRIBUTE TYPE  ATTRIBUTE VALUE
275 Interface Stability     Committed
277 MT-Level        MT-Safe
280 .SH SEE ALSO
283 \fBu8_strcmp\fR(3C), \fBu8_textprep_str\fR(3C), \fBattributes\fR(5),
284 \fBu8_strcmp\fR(9F), \fBu8_textprep_str\fR(9F), \fBu8_validate\fR(9F)
287 The Unicode Standard (http://www.unicode.org)