summaryrefslogtreecommitdiff
path: root/usr/src/man/man9f/kiconvstr.9f
blob: 9dd5686a7c6e583a053758bfb1abd43264d74e73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
'\" te
.\" 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]
.TH KICONVSTR 9F "Oct 16, 2007"
.SH NAME
kiconvstr \- string-based code conversion function
.SH SYNOPSIS
.LP
.nf
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/sunddi.h>



\fBsize_t\fR \fBkiconvstr\fR(\fBconst char *\fR\fItocode\fR, \fBconst char *\fR\fIfromcode\fR, \fBchar *\fR\fIinarray\fR,
     \fBsize_t *\fR\fIinlen\fR, \fBchar *\fR\fIoutarray\fR, \fBsize_t *\fR\fIoutlen\fR, \fBint\fR \fIflag\fR, \fBint *\fR\fIerrno\fR);
.fi

.SH INTERFACE LEVEL
.sp
.LP
Solaris DDI specific (Solaris DDI).
.SH PARAMETERS
.sp
.LP
The parameters for the \fBkiconvstr\fR function are as follows:
.sp
.ne 2
.na
\fB\fItocode\fR\fR
.ad
.RS 12n
Points to a target codeset name string. Supported names are specified at
\fBkiconv_open()\fR.
.RE

.sp
.ne 2
.na
\fB\fIfromcode\fR\fR
.ad
.RS 12n
Points to a source codeset name string. Supported names are specified at
\fBkiconv_open()\fR.
.RE

.sp
.ne 2
.na
\fB\fIinarray\fR\fR
.ad
.RS 12n
Points to a byte array containing a sequence of character bytes in
\fIfromcode\fR codeset to be converted.
.RE

.sp
.ne 2
.na
\fB\fIinlen\fR\fR
.ad
.RS 12n
As an input parameter, the number of bytes to be converted in \fIinarray\fR. As
an output parameter, the number of bytes in \fIinarray\fR still not converted
after the conversion.
.RE

.sp
.ne 2
.na
\fB\fIoutarray\fR\fR
.ad
.RS 12n
Points to a byte array where converted character bytes in \fItocode\fR codeset
can be saved.
.RE

.sp
.ne 2
.na
\fB\fIoutlen\fR\fR
.ad
.RS 12n
As an input parameter, the number of available bytes at \fIoutarray\fR where
converted character bytes can be saved. As an output parameter, the number of
bytes still available at \fIoutarray\fR after the conversion.
.RE

.sp
.ne 2
.na
\fB\fIflag\fR\fR
.ad
.RS 12n
Indicates possible conversion options constructed by a bitwise-inclusive-OR of
the following values:
.sp
.ne 2
.na
\fB\fBKICONV_IGNORE_NULL\fR\fR
.ad
.sp .6
.RS 4n
Normally, \fBkiconvstr()\fR stops the conversion if it encounters \fBNULL\fR
byte even if the current \fIinlen\fR is pointing to a value larger than zero.
.sp
If this option is set, a \fBNULL\fR byte does not stop the conversion and the
conversion continues until the number of \fIinarray\fR bytes pointed by
\fIinlen\fR are all consumed for conversion or an error happened.
.RE

.sp
.ne 2
.na
\fB\fBKICONV_REPLACE_INVALID\fR\fR
.ad
.sp .6
.RS 4n
Normally, \fBkiconvstr()\fR stops the conversion if it encounters illegal or
incomplete characters with corresponding \fIerrno\fR values.
.sp
If this option is set, \fBkiconvstr()\fR does not stop the conversion and
instead treats such characters as non-identical conversion  cases.
.RE

.RE

.sp
.ne 2
.na
\fB\fIerrno\fR\fR
.ad
.RS 12n
Indicates the error when conversion is not completed or failed. The following
are possible values:
.sp
.ne 2
.na
\fB\fBEILSEQ\fR\fR
.ad
.RS 13n
The input conversion was stopped due to an input byte that does not belong to
the input codeset.
.RE

.sp
.ne 2
.na
\fB\fBE2BIG\fR\fR
.ad
.RS 13n
The input conversion was stopped due to lack of space in the output array.
.RE

.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 13n
The input conversion was stopped due to an incomplete character or shift
sequence at the end of the input array.
.RE

.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 13n
The requested conversion is not supported.
.RE

.RE

.SH DESCRIPTION
.sp
.LP
The \fBkiconvstr()\fR function converts the sequence of characters from one
\fBcodeset\fR, in the array specified by \fIinarray\fR, into a sequence of
corresponding characters in another \fBcodeset\fR, in the array specified by
\fIoutarray\fR. The \fBcodesets\fR are those specified in \fIfromcode\fR and
\fItocode\fR parameters. The \fIinarray\fR parameter points to a character byte
array to the first character in the input array and \fIinlen\fR indicates the
number of bytes to the end of the array to be converted. The \fIoutarray\fR
parameter points to a character byte array to the first available byte in the
output array and \fIoutlen\fR indicates the number of the available bytes to
the end of the array. Unless \fBKICONV_IGNORE_NULL\fR is specified at flag,
\fBkiconvstr()\fR function normally stops when it encounters \fBNULL\fR byte
from the input array regardless of the current \fIinlen\fR value.
.sp
.LP
If \fBKICONV_REPLACE_INVALID\fR is not specified at flag and if a sequence of
input bytes does not form a valid character in the specified codeset,
conversion stops after the previous successfully converted character. If
\fBKICONV_REPLACE_INVALID\fR is not specified in \fIflag\fR and if the input
array ends with an incomplete character or shift sequence, conversion stops
after the previous successfully converted bytes. If the output array is not
large enough to hold the entire converted input, conversion stops just prior to
the input bytes that would cause the output array to overflow. The value
pointed to by \fIinlen\fR is decremented to reflect the number of bytes still
not converted in the input array. The value pointed to by \fIoutlen\fR is
decremented to reflect the number of bytes still available in the output array.
.sp
.LP
If \fBkiconvstr()\fR encounters a character in the input array that is legal,
but for which an identical character does not exist in the target
\fBcodeset\fR, \fBkiconvstr()\fR performs an implementation-defined conversion
(that is, a non-identical conversion) on this character.
.sp
.LP
If \fBKICONV_REPLACE_INVALID\fR is specified in \fIflag\fR and if
\fBkiconvstr()\fR encounters illegal or incomplete characters in the input
array, instead of stopping the conversion, \fBkiconvstr()\fR treats such
characters  as if they are non-identical characters and does non-identical
conversions on such character bytes.
.SH RETURN VALUES
.sp
.LP
The \fBkiconvstr()\fR function updates the values pointed to by the \fIinlen\fR
and \fIoutlen\fR parameters to reflect the extent of the conversion and returns
the number of non-identical conversions performed. If the entire string in the
input array is converted, the value pointed to by \fIinlen\fR is 0. If the
input conversion is stopped due to any conditions mentioned above, the value
pointed to by \fIinlen\fR is non-zero and \fIerrno\fR is set to indicate the
condition. If an error occurs, \fBkiconvstr()\fR returns (\fBsize_t\fR)-1 and
sets \fIerrno\fR to indicate the error.
.SH CONTEXT
.sp
.LP
\fBkiconvstr()\fR can be called from user or interrupt context.
.SH EXAMPLES
.LP
\fBExample 1 \fRPerforming a Code Conversion
.sp
.LP
The following example converts a \fBNULL\fR-terminated \fBISO8859-2\fR pathname
string to a \fBUTF-8\fR string and treats illegal and incomplete characters as
non-identical conversion cases. The conversion does not stop even if it
encounters a \fBNULL\fR byte from the input array.

.sp
.in +2
.nf
#include <sys/types.h>
#include <sys/errno.h>
#include <sys/sunddi.h>

        :

size_t ret;
char ib[MAXPATHLEN];
char ob[MAXPATHLEN];
size_t il, ol;
int err;

        :

/*
 * We got the pathname from somewhere.
 *
 * Calculate the length of input string including the terminating
 * NULL byte and prepare other parameters for the conversion.
 */
(void) strlcpy(ib, pathname, MAXPATHLEN);
il = strlen(ib) + 1;
ol = MAXPATHLEN;

/*
 * Do the conversion. If the ret > 0, that's the number of
 * non-identical character conversions happened during the conversion.
 * Regardless of whether we have conversion failure or not,
 * outarray could contain some converted characters.
 */
ret = kiconvstr("UTF-8", "ISO-8859-2", ib, &il, ob, &ol,
                (KICONV_IGNORE_NULL|KICONV_REPLACE_INVALID), &err);
if (ret == (size_t)-1) {
        /* Code conversion not supported? */
        if (err == EBADF)
                return (-1);

        /* Output array too small? */
        if (err == E2BIG)
                return (-2);

        /* Unknown error which isn't possible BTW. */
        return (-3);
}
.fi
.in -2

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
.TE

.SH SEE ALSO
.sp
.LP
\fBiconv\fR(3C), \fBiconv_close\fR(3C), \fBiconv_open\fR(3C),
\fBu8_strcmp\fR(3C), \fBu8_textprep_str\fR(3C), \fBu8_validate\fR(3C),
\fBuconv_u16tou32\fR(3C), \fBuconv_u16tou8\fR(3C), \fBuconv_u32tou16\fR(3C),
\fBuconv_u32tou8\fR(3C), \fBuconv_u8tou16\fR(3C), \fBuconv_u8tou32\fR(3C),
\fBattributes\fR(5), \fBkiconv\fR(9F), \fBkiconv_close\fR(9F),
\fBkiconv_open\fR(9F), \fBu8_strcmp\fR(9F), \fBu8_textprep_str\fR(9F),
\fBu8_validate\fR(9F), \fBuconv_u16tou32\fR(9F), \fBuconv_u16tou8\fR(9F),
\fBuconv_u32tou16\fR(9F), \fBuconv_u32tou8\fR(9F), \fBuconv_u8tou16\fR(9F),
\fBuconv_u8tou32\fR(9F)
.sp
.LP
The Unicode Standard:
.sp
.LP
http://www.unicode.org/standard/standard.html