xref: /titanic_50/usr/src/lib/iconv_modules/common/ucs2.h (revision 9f9b7953c22ba8b0f8372bd791fc6ecc63c69409)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef UCS2_H
28 #define UCS2_H
29 #include <sys/types.h>
30 #include <sys/isa_defs.h>
31 #include "gentypes.h"
32 
33 #define UCS2_NBYTE	2
34 #define UCS2_MAXVAL	0xfffd
35 
36 #define valid_ucs2_value(n)		(_valid_ucs2_value(n))
37 #define room_for_ucs2_cnv(p1,p2)	(((p1)+sizeof(ucs2_t))<=(p2))
38 #define no_room_for_ucs2_cnv(p1,p2) 	(((p1)+sizeof(ucs2_t))>(p2))
39 #define incomplete_ucs2_seq(p1,p2) 	(((p1)+sizeof(ucs2_t))>(p2))
40 
41 #define next_ucs2_ptr(p)    (((uchar_t*)(p))+sizeof(ucs2_t))
42 #define ext_ucs2_lsb(n)	    ((uchar_t)(((ucs2_t)(n))&((ucs2_t)0x00ff)))
43 #define ext_ucs2_msb(n)	    ((uchar_t)(((((ucs2_t)(n))&((ucs2_t)0xff00)))>>8))
44 
45 #define get_ucs2_word(p)        (*((ucs2_t*)(p)))
46 #define set_ucs2_word(p,n)	((*((ucs2_t*)(p)))=(n))
47 
48 #if defined(_BIG_ENDIAN)
49 #define get_ucs2_word_BB(p) \
50 	(((ucs2_t)((*(p))<<8))|((ucs2_t)(*((p)+1))))
51 
52 #define set_ucs2_word_BB(p,n) \
53 	(((*(p))=ext_ucs2_msb(n)),((*((p)+1))=ext_ucs2_lsb(n)))
54 
55 #else
56 #define get_ucs2_word_BB(p) \
57 	(((ucs2_t)(((*((p)+1)))<<8))|((ucs2_t)(*(p))))
58 
59 #define set_ucs2_word_BB(p,n) \
60 	((*((p)+1))=ext_ucs2_msb(n),(*(p))=ext_ucs2_lsb(n))
61 #endif
62 
63 int _valid_ucs2_value(ucs4_t);
64 #endif
65