xref: /titanic_41/usr/src/ucblib/libucb/inc/stdiom.h (revision 1e49577a7fcde812700ded04431b49d67cc57d6d)
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 usr/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 usr/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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 /*
30  * University Copyright- Copyright (c) 1982, 1986, 1988
31  * The Regents of the University of California
32  * All Rights Reserved
33  *
34  * University Acknowledgment- Portions of this document are derived from
35  * software developed by the University of California, Berkeley, and its
36  * contributors.
37  */
38 
39 #pragma ident	"%Z%%M%	%I%	%E% SMI"
40 
41 /*
42  * stdiom.h - shared guts of stdio therefore it doesn't need
43  * a surrounding #ifndef
44  */
45 
46 #ifndef _STDIOM_H
47 #define	_STDIOM_H
48 
49 typedef unsigned char	Uchar;
50 
51 #define	MAXVAL (MAXINT - (MAXINT % BUFSIZ))
52 
53 /*
54  * The number of actual pushback characters is the value
55  * of PUSHBACK plus the first byte of the buffer. The FILE buffer must,
56  * for performance reasons, start on a word aligned boundry so the value
57  * of PUSHBACK should be a multiple of word.
58  * At least 4 bytes of PUSHBACK are needed. If sizeof(int) = 1 this breaks.
59  */
60 
61 #define	PUSHBACK ((int)(((3 + sizeof (int) - 1) / sizeof (int)) * sizeof (int)))
62 
63 /* minimum buffer size must be at least 8 or shared library will break */
64 #define	_SMBFSZ (((PUSHBACK + 4) < 8) ? 8 : (PUSHBACK + 4))
65 
66 extern Uchar *_bufendtab[];
67 
68 #if BUFSIZ == 1024
69 #define	MULTIBFSZ(SZ)	((SZ) & ~0x3ff)
70 #elif BUFSIZ == 512
71 #define	MULTIBFSZ(SZ)    ((SZ) & ~0x1ff)
72 #else
73 #define	MULTIBFSZ(SZ)    ((SZ) - (SZ % BUFSIZ))
74 #endif
75 
76 #define	_bufend(iop)	_realbufend(iop)
77 #define	setbufend(iop, end)	_setbufend(iop, end)
78 
79 	/*
80 	 * Internal routines from _iob.c
81 	 */
82 extern void	_cleanup(void);
83 extern void	_flushlbf(void);
84 extern FILE	*_findiop(void);
85 extern Uchar 	*_realbufend(FILE *iop);
86 extern void	_setbufend(FILE *iop, Uchar *end);
87 extern int	_wrtchk(FILE *iop);
88 
89 	/*
90 	 * Internal routines from flush.c
91 	 */
92 extern void	_bufsync(FILE *iop, Uchar *bufend);
93 extern int	_xflsbuf(FILE *iop);
94 
95 	/*
96 	 * Internal routines from _findbuf.c
97 	 */
98 extern Uchar 	*_findbuf(FILE *iop);
99 
100 #ifndef _LP64
101 extern int _file_set(FILE *, int, const char *);
102 #define	SET_FILE(iop, fd)	(iop)->_magic = (fd); (iop)->__extendedfd = 0
103 #define	_FILE_FD_MAX		255
104 #endif
105 
106 /*
107  * The following macros improve performance of the stdio by reducing the
108  * number of calls to _bufsync and _wrtchk.  _needsync checks whether
109  * or not _bufsync needs to be called.  _WRTCHK has the same effect as
110  * _wrtchk, but often these functions have no effect, and in those cases
111  * the macros avoid the expense of calling the functions.
112  */
113 
114 #define	_needsync(p, bufend)	((bufend - (p)->_ptr) < \
115 				((p)->_cnt < 0 ? 0 : (p)->_cnt))
116 
117 #define	_WRTCHK(iop)	((((iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT) || \
118 				(iop->_base == 0) || \
119 				(iop->_ptr == iop->_base && iop->_cnt == 0 && \
120 				!(iop->_flag & (_IONBF | _IOLBF)))) \
121 			? _wrtchk(iop) : 0)
122 #endif /* _STDIOM_H */
123