xref: /illumos-gate/usr/src/lib/libc/port/stdio/data.c (revision 803376f0)
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
57257d1b4Sraf  * Common Development and Distribution License (the "License").
67257d1b4Sraf  * 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  */
217257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
237257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
30*4297a3b0SGarrett D'Amore /*
31*4297a3b0SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
32*4297a3b0SGarrett D'Amore  * Use is subject to license terms.
33*4297a3b0SGarrett D'Amore  */
347c478bd9Sstevel@tonic-gate 
357257d1b4Sraf #pragma weak __iob = _iob
367c478bd9Sstevel@tonic-gate 
377257d1b4Sraf #include "lint.h"
387c478bd9Sstevel@tonic-gate #include "mbstatet.h"
397c478bd9Sstevel@tonic-gate #include "mtlib.h"
407c478bd9Sstevel@tonic-gate #include "file64.h"
417c478bd9Sstevel@tonic-gate #include <stdio.h>
427c478bd9Sstevel@tonic-gate #include <thread.h>
437c478bd9Sstevel@tonic-gate #include <synch.h>
447c478bd9Sstevel@tonic-gate #include "stdiom.h"
457c478bd9Sstevel@tonic-gate #include <wchar.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Ptrs to start of preallocated buffers for stdin, stdout.
497c478bd9Sstevel@tonic-gate  * Some slop is allowed at the end of the buffers in case an upset in
507c478bd9Sstevel@tonic-gate  * the synchronization of _cnt and _ptr (caused by an interrupt or other
517c478bd9Sstevel@tonic-gate  * signal) is not immediately detected.
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate Uchar _sibuf[BUFSIZ + _SMBFSZ], _sobuf[BUFSIZ + _SMBFSZ];
557c478bd9Sstevel@tonic-gate Uchar _smbuf[_NFILE + 1][_SMBFSZ] = {0};  /* shared library compatibility */
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #define	DEFAULTMBSTATE \
59*4297a3b0SGarrett D'Amore 	{ 0 }
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #ifdef	_LP64
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #if _NFILE != 20
647c478bd9Sstevel@tonic-gate #error "_iob[] initialization impossible"
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate FILE _iob[_NFILE] = {
687c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, _IOREAD, RECURSIVEMUTEX, DEFAULTMBSTATE },
697c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 1, _IOWRT, RECURSIVEMUTEX, DEFAULTMBSTATE },
707c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 2, _IOWRT|_IONBF, RECURSIVEMUTEX,
717c478bd9Sstevel@tonic-gate 		DEFAULTMBSTATE },
727c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
737c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
747c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
757c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
767c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
777c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
787c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
797c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
807c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
817c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
827c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
837c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
847c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
857c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
867c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
877c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
887c478bd9Sstevel@tonic-gate 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE }
897c478bd9Sstevel@tonic-gate };
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #else
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #if _NFILE != 20 && _NFILE != 60
947c478bd9Sstevel@tonic-gate #error "_iob[] initialization impossible"
957c478bd9Sstevel@tonic-gate #endif
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * FILEs not in _iob will never reference this table, so we only need _NFILE
997c478bd9Sstevel@tonic-gate  * entries.
1007c478bd9Sstevel@tonic-gate  */
1017c478bd9Sstevel@tonic-gate struct xFILEdata _xftab[_NFILE] = {
1027c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER,
1037c478bd9Sstevel@tonic-gate 	{ 0, _smbuf[2] + _SBFSIZ, RECURSIVEMUTEX, DEFAULTMBSTATE }, /* stderr */
1047c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1057c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1067c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1077c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1087c478bd9Sstevel@tonic-gate #if _NFILE == 60
1097c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1107c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1117c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1127c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1137c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1147c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1157c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1167c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1177c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1187c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
1197c478bd9Sstevel@tonic-gate #endif
1207c478bd9Sstevel@tonic-gate 	XFILEINITIALIZER };
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate /*
1237c478bd9Sstevel@tonic-gate  * Ptrs to end of read/write buffers for first _NFILE devices.
1247c478bd9Sstevel@tonic-gate  * There is an extra bufend pointer which corresponds to the dummy
1257c478bd9Sstevel@tonic-gate  * file number _NFILE, which is used by sscanf and sprintf.
1267c478bd9Sstevel@tonic-gate  * Our implementation makes sure it never references _realbufend/_reallock/
1277c478bd9Sstevel@tonic-gate  * etc for *sscanf() and *sprintf(); such use of a shared item would not be
1287c478bd9Sstevel@tonic-gate  * thread safe.
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate Uchar *_bufendtab[_NFILE+1] = { NULL, NULL, _smbuf[2] + _SBFSIZ, };
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate FILE _iob[_NFILE] = {
1337c478bd9Sstevel@tonic-gate 	{ 0, NULL, NULL, _IOREAD, 0 },
1347c478bd9Sstevel@tonic-gate 	{ 0, NULL, NULL, _IOWRT, 1 },
1357c478bd9Sstevel@tonic-gate 	{ 0, NULL, NULL, _IOWRT|_IONBF, 2 },
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * Ptr to end of io control blocks
1407c478bd9Sstevel@tonic-gate  */
1417c478bd9Sstevel@tonic-gate FILE *_lastbuf = &_iob[_NFILE];
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #endif	/*	_LP64	*/
144