/*
* CDDL HEADER START
*
* 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
* 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]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <sys/byteorder.h>
#include <sys/u8_textprep.h>
#include <sys/kiconv_cck_common.h>
#include <sys/kiconv_sc.h>
#include <sys/kiconv_gb18030_utf8.h>
#include <sys/kiconv_gb2312_utf8.h>
#include <sys/kiconv_utf8_gb18030.h>
#include <sys/kiconv_utf8_gb2312.h>
static void *
{
return ((void *)KICONV_SC_GB18030);
}
static void *
{
return ((void *)KICONV_SC_GBK);
}
static void *
{
return ((void *)KICONV_SC_EUCCN);
}
static int
close_fr_sc(void *s)
{
if ((uintptr_t)s > KICONV_SC_MAX_MAGIC_ID)
return (EBADF);
return (0);
}
/*
* Encoding convertor from UTF-8 to GB18030.
*/
{
}
/*
* String based encoding convertor from UTF-8 to GB18030.
*/
{
}
/*
* Encoding convertor from GB18030 to UTF-8.
*/
{
/* Check on the kiconv code conversion descriptor. */
return ((size_t)-1);
}
/* If this is a state reset request, process and return. */
return (0);
}
ret_val = 0;
if (KICONV_IS_ASCII(*ib)) {
}
continue;
}
/*
* Issue EILSEQ error if the first byte is not a
* valid GB18030 leading byte.
*/
if (! KICONV_SC_IS_GBK_1st_BYTE(*ib)) {
}
if (isgbk4) {
}
}
} else {
}
}
}
if (sz < 0) {
}
}
return (ret_val);
}
/*
* String based encoding convertor from GB18030 to UTF-8.
*/
{
ret_val = 0;
break;
if (KICONV_IS_ASCII(*ib)) {
}
continue;
}
if (! KICONV_SC_IS_GBK_1st_BYTE(*ib)) {
}
if (isgbk4) {
if (flag & KICONV_REPLACE_INVALID) {
goto REPLACE_INVALID;
}
}
}
} else {
if (flag & KICONV_REPLACE_INVALID) {
goto REPLACE_INVALID;
}
}
}
}
if (sz < 0) {
}
continue;
}
ret_val++;
}
return (ret_val);
}
/*
* Encoding convertor from UTF-8 to GBK.
*/
{
}
/*
* String based encoding convertor from UTF-8 to GBK.
*/
{
}
/*
* Encoding convertor from GBK to UTF-8.
*/
{
/* Check on the kiconv code conversion descriptor. */
return ((size_t)-1);
}
/* If this is a state reset request, process and return. */
return (0);
}
ret_val = 0;
if (KICONV_IS_ASCII(*ib)) {
}
continue;
}
/*
* Issue EILSEQ error if the first byte is not a
* valid GBK leading byte.
*/
if (! KICONV_SC_IS_GBK_1st_BYTE(*ib)) {
}
/*
* Issue EINVAL error if input buffer has an incomplete
* character at the end of the buffer.
*/
}
/*
* Issue EILSEQ error if the remaining byte is not
* a valid GBK byte.
*/
}
/* Now we have a valid GBK character. */
if (sz < 0) {
}
ib += 2;
}
return (ret_val);
}
/*
* String based encoding convertor from GBK to UTF-8.
*/
{
ret_val = 0;
break;
if (KICONV_IS_ASCII(*ib)) {
}
continue;
}
if (! KICONV_SC_IS_GBK_1st_BYTE(*ib)) {
}
}
}
if (sz < 0) {
}
ib += 2;
continue;
}
ret_val++;
}
return (ret_val);
}
/*
* Encoding convertor from UTF-8 to EUC-CN.
*/
{
}
/*
* String based encoding convertor from UTF-8 to EUC-CN.
*/
{
}
/*
* Encoding converto from EUC-CN to UTF-8 code.
*/
{
/* Check on the kiconv code conversion descriptor. */
return ((size_t)-1);
}
/* If this is a state reset request, process and return. */
return (0);
}
ret_val = 0;
if (KICONV_IS_ASCII(*ib)) {
}
continue;
}
/*
* Issue EILSEQ error if the first byte is not a
* valid GB2312 leading byte.
*/
if (! KICONV_SC_IS_GB2312_BYTE(*ib)) {
}
/*
* Issue EINVAL error if input buffer has an incomplete
* character at the end of the buffer.
*/
}
/*
* Issue EILSEQ error if the remaining byte is not
* a valid GB2312 byte.
*/
}
/* Now we have a valid GB2312 character */
if (sz < 0) {
}
ib += 2;
}
return (ret_val);
}
/*
* String based encoding convertor from EUC-CN to UTF-8.
*/
{
ret_val = 0;
break;
if (KICONV_IS_ASCII(*ib)) {
}
continue;
}
if (! KICONV_SC_IS_GB2312_BYTE(*ib)) {
}
}
}
if (sz < 0) {
}
ib += 2;
continue;
}
ret_val++;
}
return (ret_val);
}
/*
* Convert single GB2312 character to UTF-8.
* Return: > 0 - Converted successfully
* = -1 - E2BIG
*/
static int8_t
{
/* index = (b1 - KICONV_EUC_START) * 94 + b2 - KICONV_EUC_START; */
if (index >= KICONV_GB2312_UTF8_MAX)
return (-1);
}
/*
* As kiconv_gb2312_utf8 contain muliple KICONV_UTF8_REPLACEMENT_CHAR
* elements, so need to ckeck more.
*/
if (sz == KICONV_UTF8_REPLACEMENT_CHAR_LEN &&
u8[0] == KICONV_UTF8_REPLACEMENT_CHAR1 &&
(*ret_val)++;
return (sz);
}
/*
* Convert single GB18030 or GBK character to UTF-8.
* Return: > 0 - Converted successfully
* = -1 - E2BIG
*/
static int8_t
{
if (isgbk4) {
if (gbk_val >= KICONV_SC_PLANE1_GB18030_START) {
/*
* u32 = ((gbk_val >> 24) - 0x90) * 12600 +
* (((gbk_val & 0xFF0000) >> 16) - 0x30) * 1260 +
* (((gbk_val & 0xFF00) >> 8) - 0x81) * 10 +
* (gbk_val & 0xFF - 0x30)+
* KICONV_SC_PLANE1_UCS4_START;
*/
index = 1;
} else {
}
} else {
}
return (-1);
}
if (index == 0)
(*ret_val)++; /* Non-identical conversion */
return (sz);
}
/*
* Convert single UTF-8 character to GB18030.
* Return: > 0 - Converted successfully
* = -1 - E2BIG
*/
/* ARGSUSED */
static int8_t
{
if (utf8 >= KICONV_SC_PLANE1_UTF8_START) {
/* Four bytes GB18030 [0x90308130, 0xe339fe39] handling. */
gbklen = 4;
index = 1;
} else {
}
return (-1);
}
if (index == 0)
(*ret)++; /* Non-identical conversion */
if (gbklen == 2) {
} else if (gbklen == 4) {
}
return (gbklen);
}
/*
* Convert single UTF-8 character to GBK.
* Return: > 0 - Converted successfully
* = -1 - E2BIG
*/
/* ARGSUSED */
static int8_t
{
/* GBK and GB18030 share the same table, so check the length. */
if (gbklen == 4) {
index = 0;
gbklen = 1;
}
return (-1);
}
if (index == 0)
(*ret)++; /* Non-identical conversion */
if (gbklen > 1)
return (gbklen);
}
/*
* Convert single UTF-8 character to GB2312.
* Return: > 0 - Converted successfully
* = -1 - E2BIG
*/
/* ARGSUSED */
static int8_t
{
return (-1);
}
if (index == 0)
(*ret)++;
if (gblen > 1)
return (gblen);
}
{
},
{
},
{
},
{
},
{
},
{
},
};
"kiconv_sc", /* module name */
sizeof (kiconv_sc_ops_tbl) / sizeof (kiconv_sc_ops_tbl[0]),
0,
NULL,
NULL,
0
};
"kiconv Simplified Chinese module 1.0",
};
(void *)&modlkiconv_sc,
};
int
_init(void)
{
int err;
if (err)
return (err);
}
int
_fini(void)
{
int err;
/*
* If this module is being used, then, we cannot remove the module.
* The following checking will catch pretty much all usual cases.
*
* Any remaining will be catached by the kiconv_unregister_module()
* during mod_remove() at below.
*/
return (EBUSY);
if (err)
return (err);
}
int
{
}