4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1989 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/types.h>
35 #define EUCMASK 0x8080 /* All id bits */
36 #define MASK0 0x0000 /* Code Set 0 */
37 #define MASK1 0x8080 /* Code Set 1 */
38 #define MASK2 0x0080 /* Code Set 2 */
39 #define MASK3 0x8000 /* Code Set 3 */
41 #define EUCWID1 eucinfo->_eucw1
42 #define EUCWID2 eucinfo->_eucw2
43 #define EUCWID3 eucinfo->_eucw3
45 int _wctomb_euc(char *, wchar_t);
48 _mbtowc_euc(wchar_t *wchar
, char *s
, size_t n
)
53 char *olds
= (char *)s
;
55 eucwidth_t
* eucinfo
= (eucwidth_t
*)_code_set_info
.code_info
;
61 c
= (unsigned char)*s
++;
69 if(!(length
= EUCWID2
)) {
76 if(!(length
= EUCWID3
)) {
95 if((c
= (unsigned char)*s
++) < 0200 || iscntrl(c
))
97 intcode
= (intcode
<< 8) | (c
& 0177);
100 *wchar
= intcode
| mask
;
101 return ((char *)s
- olds
);
106 _mbstowcs_euc(wchar_t *pwcs
, char *s
, size_t n
)
114 i
=_mbtowc_euc(pwcs
+j
, s
, MB_LEN_MAX
);
127 _wcstombs_euc(char *s
, wchar_t *pwcs
, size_t n
)
131 int r
=n
; /* Rest of bytes. */
133 char mbbuf
[MB_LEN_MAX
+1];
135 while(wc
=(*pwcs
++)) {
136 i
=_wctomb_euc(mbbuf
, wc
);
140 if (i
==-1) return (-1);
143 for (t
=mbbuf
;i
>0;--i
){
144 /* Copy each byte. */
149 /* Has enough room for NUL. */
155 _wctomb_euc(char *s
, wchar_t wchar
)
157 eucwidth_t
* eucinfo
= (eucwidth_t
*)_code_set_info
.code_info
;
163 if( wchar
<= 0177 || wchar
<= 0377 && iscntrl(wchar
)) {
165 return (wchar
? 1 : 0);
167 switch(wchar
& EUCMASK
) {
194 return (s
+ size
- olds
);