10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1846Scraigm * Common Development and Distribution License (the "License"). 6*1846Scraigm * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1846Scraigm * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 270Sstevel@tonic-gate /* All Rights Reserved */ 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 310Sstevel@tonic-gate * The Regents of the University of California 320Sstevel@tonic-gate * All Rights Reserved 330Sstevel@tonic-gate * 340Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 350Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 360Sstevel@tonic-gate * contributors. 370Sstevel@tonic-gate */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 400Sstevel@tonic-gate 410Sstevel@tonic-gate /* 420Sstevel@tonic-gate * stdiom.h - shared guts of stdio therefore it doesn't need 430Sstevel@tonic-gate * a surrounding #ifndef 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate 460Sstevel@tonic-gate #ifndef _STDIOM_H 470Sstevel@tonic-gate #define _STDIOM_H 480Sstevel@tonic-gate 490Sstevel@tonic-gate typedef unsigned char Uchar; 500Sstevel@tonic-gate 510Sstevel@tonic-gate #define MAXVAL (MAXINT - (MAXINT % BUFSIZ)) 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* 540Sstevel@tonic-gate * The number of actual pushback characters is the value 550Sstevel@tonic-gate * of PUSHBACK plus the first byte of the buffer. The FILE buffer must, 560Sstevel@tonic-gate * for performance reasons, start on a word aligned boundry so the value 570Sstevel@tonic-gate * of PUSHBACK should be a multiple of word. 580Sstevel@tonic-gate * At least 4 bytes of PUSHBACK are needed. If sizeof(int) = 1 this breaks. 590Sstevel@tonic-gate */ 600Sstevel@tonic-gate 610Sstevel@tonic-gate #define PUSHBACK ((int)(((3 + sizeof (int) - 1) / sizeof (int)) * sizeof (int))) 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* minimum buffer size must be at least 8 or shared library will break */ 640Sstevel@tonic-gate #define _SMBFSZ (((PUSHBACK + 4) < 8) ? 8 : (PUSHBACK + 4)) 650Sstevel@tonic-gate 660Sstevel@tonic-gate extern Uchar *_bufendtab[]; 670Sstevel@tonic-gate 680Sstevel@tonic-gate #if BUFSIZ == 1024 690Sstevel@tonic-gate #define MULTIBFSZ(SZ) ((SZ) & ~0x3ff) 700Sstevel@tonic-gate #elif BUFSIZ == 512 710Sstevel@tonic-gate #define MULTIBFSZ(SZ) ((SZ) & ~0x1ff) 720Sstevel@tonic-gate #else 730Sstevel@tonic-gate #define MULTIBFSZ(SZ) ((SZ) - (SZ % BUFSIZ)) 740Sstevel@tonic-gate #endif 750Sstevel@tonic-gate 760Sstevel@tonic-gate #define _bufend(iop) _realbufend(iop) 770Sstevel@tonic-gate #define setbufend(iop, end) _setbufend(iop, end) 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 800Sstevel@tonic-gate * Internal routines from _iob.c 810Sstevel@tonic-gate */ 820Sstevel@tonic-gate extern void _cleanup(void); 830Sstevel@tonic-gate extern void _flushlbf(void); 840Sstevel@tonic-gate extern FILE *_findiop(void); 850Sstevel@tonic-gate extern Uchar *_realbufend(FILE *iop); 860Sstevel@tonic-gate extern void _setbufend(FILE *iop, Uchar *end); 870Sstevel@tonic-gate extern int _wrtchk(FILE *iop); 880Sstevel@tonic-gate 890Sstevel@tonic-gate /* 900Sstevel@tonic-gate * Internal routines from flush.c 910Sstevel@tonic-gate */ 920Sstevel@tonic-gate extern void _bufsync(FILE *iop, Uchar *bufend); 930Sstevel@tonic-gate extern int _xflsbuf(FILE *iop); 940Sstevel@tonic-gate 950Sstevel@tonic-gate /* 960Sstevel@tonic-gate * Internal routines from _findbuf.c 970Sstevel@tonic-gate */ 980Sstevel@tonic-gate extern Uchar *_findbuf(FILE *iop); 990Sstevel@tonic-gate 100*1846Scraigm #ifndef _LP64 101*1846Scraigm extern int _file_set(FILE *, int, const char *); 102*1846Scraigm #define SET_FILE(iop, fd) (iop)->_magic = (fd); (iop)->__extendedfd = 0 103*1846Scraigm #define _FILE_FD_MAX 255 104*1846Scraigm #endif 105*1846Scraigm 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * The following macros improve performance of the stdio by reducing the 1080Sstevel@tonic-gate * number of calls to _bufsync and _wrtchk. _needsync checks whether 1090Sstevel@tonic-gate * or not _bufsync needs to be called. _WRTCHK has the same effect as 1100Sstevel@tonic-gate * _wrtchk, but often these functions have no effect, and in those cases 1110Sstevel@tonic-gate * the macros avoid the expense of calling the functions. 1120Sstevel@tonic-gate */ 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate #define _needsync(p, bufend) ((bufend - (p)->_ptr) < \ 1150Sstevel@tonic-gate ((p)->_cnt < 0 ? 0 : (p)->_cnt)) 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate #define _WRTCHK(iop) ((((iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT) || \ 1180Sstevel@tonic-gate (iop->_base == 0) || \ 1190Sstevel@tonic-gate (iop->_ptr == iop->_base && iop->_cnt == 0 && \ 1200Sstevel@tonic-gate !(iop->_flag & (_IONBF | _IOLBF)))) \ 1210Sstevel@tonic-gate ? _wrtchk(iop) : 0) 1220Sstevel@tonic-gate #endif /* _STDIOM_H */ 123