xref: /titanic_52/usr/src/lib/libc/inc/mse.h (revision 2bc987325e3ded1865bff043128661815c4690b9)
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  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef	_MSE_H
32 #define	_MSE_H
33 
34 #include "lint.h"
35 #include "file64.h"
36 #include <stdio.h>
37 #include <wchar.h>
38 #include <string.h>
39 #include "stdiom.h"
40 
41 typedef enum {
42 	_NO_MODE,					/* not bound */
43 	_BYTE_MODE,					/* Byte orientation */
44 	_WC_MODE					/* Wide orientation */
45 } _IOP_orientation_t;
46 
47 /*
48  * DESCRIPTION:
49  * This function gets the pointer to the mbstate_t structure associated
50  * with the specified iop.
51  *
52  * RETURNS:
53  * If the associated mbstate_t found, the pointer to the mbstate_t is
54  * returned.  Otherwise, (mbstate_t *)NULL is returned.
55  */
56 #ifdef _LP64
57 #define	_getmbstate(iop)	(&(iop)->_state)
58 #else
59 extern mbstate_t	*_getmbstate(FILE *);
60 #endif
61 
62 /*
63  * DESCRIPTION:
64  * This function/macro gets the orientation bound to the specified iop.
65  *
66  * RETURNS:
67  * _WC_MODE	if iop has been bound to Wide orientation
68  * _BYTE_MODE	if iop has been bound to Byte orientation
69  * _NO_MODE	if iop has been bound to neither Wide nor Byte
70  */
71 extern _IOP_orientation_t	_getorientation(FILE *);
72 
73 /*
74  * DESCRIPTION:
75  * This function/macro sets the orientation to the specified iop.
76  *
77  * INPUT:
78  * flag may take one of the following:
79  *	_WC_MODE	Wide orientation
80  *	_BYTE_MODE	Byte orientation
81  *	_NO_MODE	Unoriented
82  */
83 extern void	_setorientation(FILE *, _IOP_orientation_t);
84 
85 /*
86  * From page 32 of XSH5
87  * Once a wide-character I/O function has been applied
88  * to a stream without orientation, the stream becomes
89  * wide-orientated.  Similarly, once a byte I/O function
90  * has been applied to a stream without orientation,
91  * the stream becomes byte-orientated.  Only a call to
92  * the freopen() function or the fwide() function can
93  * otherwise alter the orientation of a stream.
94  */
95 
96 #define	_SET_ORIENTATION_BYTE(iop) \
97 { \
98 	if (GET_NO_MODE(iop)) \
99 		_setorientation(iop, _BYTE_MODE); \
100 }
101 
102 #endif	/* _MSE_H */
103