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> size_t kiconvstr(const char *tocode, const char *fromcode, char *inarray, size_t *inlen, char *outarray, size_t *outlen, int flag, int *errno);
Points to a target codeset name string. Supported names are specified at kiconv_open().
Points to a source codeset name string. Supported names are specified at kiconv_open().
Points to a byte array containing a sequence of character bytes in fromcode codeset to be converted.
As an input parameter, the number of bytes to be converted in inarray. As an output parameter, the number of bytes in inarray still not converted after the conversion.
Points to a byte array where converted character bytes in tocode codeset can be saved.
As an input parameter, the number of available bytes at outarray where converted character bytes can be saved. As an output parameter, the number of bytes still available at outarray after the conversion.
Indicates possible conversion options constructed by a bitwise-inclusive-OR of the following values: KICONV_IGNORE_NULL
Normally, kiconvstr() stops the conversion if it encounters NULL byte even if the current inlen is pointing to a value larger than zero. If this option is set, a NULL byte does not stop the conversion and the conversion continues until the number of inarray bytes pointed by inlen are all consumed for conversion or an error happened.
Normally, kiconvstr() stops the conversion if it encounters illegal or incomplete characters with corresponding errno values. If this option is set, kiconvstr() does not stop the conversion and instead treats such characters as non-identical conversion cases.
Indicates the error when conversion is not completed or failed. The following are possible values: EILSEQ
The input conversion was stopped due to an input byte that does not belong to the input codeset.
The input conversion was stopped due to lack of space in the output array.
The input conversion was stopped due to an incomplete character or shift sequence at the end of the input array.
The requested conversion is not supported.
If KICONV_REPLACE_INVALID 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 KICONV_REPLACE_INVALID is not specified in flag 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 inlen is decremented to reflect the number of bytes still not converted in the input array. The value pointed to by outlen is decremented to reflect the number of bytes still available in the output array.
If kiconvstr() encounters a character in the input array that is legal, but for which an identical character does not exist in the target codeset, kiconvstr() performs an implementation-defined conversion (that is, a non-identical conversion) on this character.
If KICONV_REPLACE_INVALID is specified in flag and if kiconvstr() encounters illegal or incomplete characters in the input array, instead of stopping the conversion, kiconvstr() treats such characters as if they are non-identical characters and does non-identical conversions on such character bytes.
The following example converts a NULL-terminated ISO8859-2 pathname string to a UTF-8 string and treats illegal and incomplete characters as non-identical conversion cases. The conversion does not stop even if it encounters a NULL byte from the input array.
#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); }
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Committed |
The Unicode Standard:
http://www.unicode.org/standard/standard.html