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