xref: /titanic_50/usr/src/ucblib/libucb/inc/stdiom.h (revision a5f69788de7ac07553de47f7fec8c05a9a94c105)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*a5f69788Scraigm  * Common Development and Distribution License (the "License").
6*a5f69788Scraigm  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*a5f69788Scraigm  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate  * The Regents of the University of California
327c478bd9Sstevel@tonic-gate  * All Rights Reserved
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate  * contributors.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * stdiom.h - shared guts of stdio therefore it doesn't need
437c478bd9Sstevel@tonic-gate  * a surrounding #ifndef
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifndef _STDIOM_H
477c478bd9Sstevel@tonic-gate #define	_STDIOM_H
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate typedef unsigned char	Uchar;
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	MAXVAL (MAXINT - (MAXINT % BUFSIZ))
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * The number of actual pushback characters is the value
557c478bd9Sstevel@tonic-gate  * of PUSHBACK plus the first byte of the buffer. The FILE buffer must,
567c478bd9Sstevel@tonic-gate  * for performance reasons, start on a word aligned boundry so the value
577c478bd9Sstevel@tonic-gate  * of PUSHBACK should be a multiple of word.
587c478bd9Sstevel@tonic-gate  * At least 4 bytes of PUSHBACK are needed. If sizeof(int) = 1 this breaks.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #define	PUSHBACK ((int)(((3 + sizeof (int) - 1) / sizeof (int)) * sizeof (int)))
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /* minimum buffer size must be at least 8 or shared library will break */
647c478bd9Sstevel@tonic-gate #define	_SMBFSZ (((PUSHBACK + 4) < 8) ? 8 : (PUSHBACK + 4))
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate extern Uchar *_bufendtab[];
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #if BUFSIZ == 1024
697c478bd9Sstevel@tonic-gate #define	MULTIBFSZ(SZ)	((SZ) & ~0x3ff)
707c478bd9Sstevel@tonic-gate #elif BUFSIZ == 512
717c478bd9Sstevel@tonic-gate #define	MULTIBFSZ(SZ)    ((SZ) & ~0x1ff)
727c478bd9Sstevel@tonic-gate #else
737c478bd9Sstevel@tonic-gate #define	MULTIBFSZ(SZ)    ((SZ) - (SZ % BUFSIZ))
747c478bd9Sstevel@tonic-gate #endif
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate #define	_bufend(iop)	_realbufend(iop)
777c478bd9Sstevel@tonic-gate #define	setbufend(iop, end)	_setbufend(iop, end)
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	/*
807c478bd9Sstevel@tonic-gate 	 * Internal routines from _iob.c
817c478bd9Sstevel@tonic-gate 	 */
827c478bd9Sstevel@tonic-gate extern void	_cleanup(void);
837c478bd9Sstevel@tonic-gate extern void	_flushlbf(void);
847c478bd9Sstevel@tonic-gate extern FILE	*_findiop(void);
857c478bd9Sstevel@tonic-gate extern Uchar 	*_realbufend(FILE *iop);
867c478bd9Sstevel@tonic-gate extern void	_setbufend(FILE *iop, Uchar *end);
877c478bd9Sstevel@tonic-gate extern int	_wrtchk(FILE *iop);
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	/*
907c478bd9Sstevel@tonic-gate 	 * Internal routines from flush.c
917c478bd9Sstevel@tonic-gate 	 */
927c478bd9Sstevel@tonic-gate extern void	_bufsync(FILE *iop, Uchar *bufend);
937c478bd9Sstevel@tonic-gate extern int	_xflsbuf(FILE *iop);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	/*
967c478bd9Sstevel@tonic-gate 	 * Internal routines from _findbuf.c
977c478bd9Sstevel@tonic-gate 	 */
987c478bd9Sstevel@tonic-gate extern Uchar 	*_findbuf(FILE *iop);
997c478bd9Sstevel@tonic-gate 
100*a5f69788Scraigm #ifndef _LP64
101*a5f69788Scraigm extern int _file_set(FILE *, int, const char *);
102*a5f69788Scraigm #define	SET_FILE(iop, fd)	(iop)->_magic = (fd); (iop)->__extendedfd = 0
103*a5f69788Scraigm #define	_FILE_FD_MAX		255
104*a5f69788Scraigm #endif
105*a5f69788Scraigm 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * The following macros improve performance of the stdio by reducing the
1087c478bd9Sstevel@tonic-gate  * number of calls to _bufsync and _wrtchk.  _needsync checks whether
1097c478bd9Sstevel@tonic-gate  * or not _bufsync needs to be called.  _WRTCHK has the same effect as
1107c478bd9Sstevel@tonic-gate  * _wrtchk, but often these functions have no effect, and in those cases
1117c478bd9Sstevel@tonic-gate  * the macros avoid the expense of calling the functions.
1127c478bd9Sstevel@tonic-gate  */
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	_needsync(p, bufend)	((bufend - (p)->_ptr) < \
1157c478bd9Sstevel@tonic-gate 				((p)->_cnt < 0 ? 0 : (p)->_cnt))
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #define	_WRTCHK(iop)	((((iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT) || \
1187c478bd9Sstevel@tonic-gate 				(iop->_base == 0) || \
1197c478bd9Sstevel@tonic-gate 				(iop->_ptr == iop->_base && iop->_cnt == 0 && \
1207c478bd9Sstevel@tonic-gate 				!(iop->_flag & (_IONBF | _IOLBF)))) \
1217c478bd9Sstevel@tonic-gate 			? _wrtchk(iop) : 0)
1227c478bd9Sstevel@tonic-gate #endif /* _STDIOM_H */
123