xref: /titanic_41/usr/src/lib/libc/inc/mse.h (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_MSE_H
28 #define	_MSE_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <wchar.h>
34 #include <string.h>
35 #include "stdiom.h"
36 
37 typedef enum {
38 	_NO_MODE,					/* not bound */
39 	_BYTE_MODE,					/* Byte orientation */
40 	_WC_MODE					/* Wide orientation */
41 } _IOP_orientation_t;
42 
43 /*
44  * DESCRIPTION:
45  * This function gets the pointer to the mbstate_t structure associated
46  * with the specified iop.
47  *
48  * RETURNS:
49  * If the associated mbstate_t found, the pointer to the mbstate_t is
50  * returned.  Otherwise, (mbstate_t *)NULL is returned.
51  */
52 #ifdef _LP64
53 #define	_getmbstate(iop)	(&(iop)->_state)
54 #else
55 extern mbstate_t	*_getmbstate(FILE *);
56 #endif
57 
58 /*
59  * DESCRIPTION:
60  * This function/macro gets the orientation bound to the specified iop.
61  *
62  * RETURNS:
63  * _WC_MODE	if iop has been bound to Wide orientation
64  * _BYTE_MODE	if iop has been bound to Byte orientation
65  * _NO_MODE	if iop has been bound to neither Wide nor Byte
66  */
67 extern _IOP_orientation_t	_getorientation(FILE *);
68 
69 /*
70  * DESCRIPTION:
71  * This function/macro sets the orientation to the specified iop.
72  *
73  * INPUT:
74  * flag may take one of the following:
75  *	_WC_MODE	Wide orientation
76  *	_BYTE_MODE	Byte orientation
77  *	_NO_MODE	Unoriented
78  */
79 extern void	_setorientation(FILE *, _IOP_orientation_t);
80 
81 /*
82  * From page 32 of XSH5
83  * Once a wide-character I/O function has been applied
84  * to a stream without orientation, the stream becomes
85  * wide-orientated.  Similarly, once a byte I/O function
86  * has been applied to a stream without orientation,
87  * the stream becomes byte-orientated.  Only a call to
88  * the freopen() function or the fwide() function can
89  * otherwise alter the orientation of a stream.
90  */
91 
92 /*
93  * libc_i18n provides the following functions:
94  */
95 extern int	_set_orientation_wide(FILE *, void **, void (*(*))(void), int);
96 extern void	*__mbst_get_lc_and_fp(const mbstate_t *,
97     void (*(*))(void), int);
98 /*
99  * Above two functions take either FP_WCTOMB or FP_FGETWC for the integer
100  * argument.
101  */
102 #define	FP_WCTOMB	0
103 #define	FP_FGETWC	1
104 
105 #define	_SET_ORIENTATION_BYTE(iop) \
106 { \
107 	if (GET_NO_MODE(iop)) \
108 		_setorientation(iop, _BYTE_MODE); \
109 }
110 
111 /* The following is specified in the argument of _get_internal_mbstate() */
112 #define	_MBRLEN		0
113 #define	_MBRTOWC	1
114 #define	_WCRTOMB	2
115 #define	_MBSRTOWCS	3
116 #define	_WCSRTOMBS	4
117 #define	_MAX_MB_FUNC	_WCSRTOMBS
118 
119 extern void	_clear_internal_mbstate(void);
120 extern mbstate_t	*_get_internal_mbstate(int);
121 
122 #define	MBSTATE_INITIAL(ps)	MBSTATE_RESTART(ps)
123 #define	MBSTATE_RESTART(ps) \
124 	(void) memset((void *)ps, 0, sizeof (mbstate_t))
125 
126 #endif	/* _MSE_H */
127