xref: /onnv-gate/usr/src/lib/libc/port/stdio/data.c (revision 6812:febeba71273d)
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*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * 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  */
21*6812Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
30*6812Sraf #pragma ident	"%Z%%M%	%I%	%E% SMI"
310Sstevel@tonic-gate 
32*6812Sraf #pragma weak __iob = _iob
330Sstevel@tonic-gate 
34*6812Sraf #include "lint.h"
350Sstevel@tonic-gate #include "mbstatet.h"
360Sstevel@tonic-gate #include "mtlib.h"
370Sstevel@tonic-gate #include "file64.h"
380Sstevel@tonic-gate #include <stdio.h>
390Sstevel@tonic-gate #include <thread.h>
400Sstevel@tonic-gate #include <synch.h>
410Sstevel@tonic-gate #include "stdiom.h"
420Sstevel@tonic-gate #include <wchar.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * Ptrs to start of preallocated buffers for stdin, stdout.
460Sstevel@tonic-gate  * Some slop is allowed at the end of the buffers in case an upset in
470Sstevel@tonic-gate  * the synchronization of _cnt and _ptr (caused by an interrupt or other
480Sstevel@tonic-gate  * signal) is not immediately detected.
490Sstevel@tonic-gate  */
500Sstevel@tonic-gate 
510Sstevel@tonic-gate Uchar _sibuf[BUFSIZ + _SMBFSZ], _sobuf[BUFSIZ + _SMBFSZ];
520Sstevel@tonic-gate Uchar _smbuf[_NFILE + 1][_SMBFSZ] = {0};  /* shared library compatibility */
530Sstevel@tonic-gate 
540Sstevel@tonic-gate 
550Sstevel@tonic-gate #define	DEFAULTMBSTATE \
560Sstevel@tonic-gate 	{ NULL, NULL, {0, 0, 0, 0, 0, 0, 0, 0}, 0, {0, 0}}
570Sstevel@tonic-gate 
580Sstevel@tonic-gate #ifdef	_LP64
590Sstevel@tonic-gate 
600Sstevel@tonic-gate #if _NFILE != 20
610Sstevel@tonic-gate #error "_iob[] initialization impossible"
620Sstevel@tonic-gate #endif
630Sstevel@tonic-gate 
640Sstevel@tonic-gate FILE _iob[_NFILE] = {
650Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, _IOREAD, RECURSIVEMUTEX, DEFAULTMBSTATE },
660Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 1, _IOWRT, RECURSIVEMUTEX, DEFAULTMBSTATE },
670Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 2, _IOWRT|_IONBF, RECURSIVEMUTEX,
680Sstevel@tonic-gate 		DEFAULTMBSTATE },
690Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
700Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
710Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
720Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
730Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
740Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
750Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
760Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
770Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
780Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
790Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
800Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
810Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
820Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
830Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
840Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
850Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE }
860Sstevel@tonic-gate };
870Sstevel@tonic-gate 
880Sstevel@tonic-gate #else
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #if _NFILE != 20 && _NFILE != 60
910Sstevel@tonic-gate #error "_iob[] initialization impossible"
920Sstevel@tonic-gate #endif
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /*
950Sstevel@tonic-gate  * FILEs not in _iob will never reference this table, so we only need _NFILE
960Sstevel@tonic-gate  * entries.
970Sstevel@tonic-gate  */
980Sstevel@tonic-gate struct xFILEdata _xftab[_NFILE] = {
990Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER,
1000Sstevel@tonic-gate 	{ 0, _smbuf[2] + _SBFSIZ, RECURSIVEMUTEX, DEFAULTMBSTATE }, /* stderr */
1010Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1020Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1030Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1040Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1050Sstevel@tonic-gate #if _NFILE == 60
1060Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1070Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1080Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1090Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1100Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1110Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1120Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1130Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1140Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1150Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate 	XFILEINITIALIZER };
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate  * Ptrs to end of read/write buffers for first _NFILE devices.
1210Sstevel@tonic-gate  * There is an extra bufend pointer which corresponds to the dummy
1220Sstevel@tonic-gate  * file number _NFILE, which is used by sscanf and sprintf.
1230Sstevel@tonic-gate  * Our implementation makes sure it never references _realbufend/_reallock/
1240Sstevel@tonic-gate  * etc for *sscanf() and *sprintf(); such use of a shared item would not be
1250Sstevel@tonic-gate  * thread safe.
1260Sstevel@tonic-gate  */
1270Sstevel@tonic-gate Uchar *_bufendtab[_NFILE+1] = { NULL, NULL, _smbuf[2] + _SBFSIZ, };
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate FILE _iob[_NFILE] = {
1300Sstevel@tonic-gate 	{ 0, NULL, NULL, _IOREAD, 0 },
1310Sstevel@tonic-gate 	{ 0, NULL, NULL, _IOWRT, 1 },
1320Sstevel@tonic-gate 	{ 0, NULL, NULL, _IOWRT|_IONBF, 2 },
1330Sstevel@tonic-gate };
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate /*
1360Sstevel@tonic-gate  * Ptr to end of io control blocks
1370Sstevel@tonic-gate  */
1380Sstevel@tonic-gate FILE *_lastbuf = &_iob[_NFILE];
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate #endif	/*	_LP64	*/
141