xref: /titanic_41/usr/src/lib/libc/port/stdio/data.c (revision ed5289f91b9bf164dccd6c75398362be77a4478d)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #pragma weak __iob = _iob
33 
34 #include "lint.h"
35 #include "mbstatet.h"
36 #include "mtlib.h"
37 #include "file64.h"
38 #include <stdio.h>
39 #include <thread.h>
40 #include <synch.h>
41 #include "stdiom.h"
42 #include <wchar.h>
43 
44 /*
45  * Ptrs to start of preallocated buffers for stdin, stdout.
46  * Some slop is allowed at the end of the buffers in case an upset in
47  * the synchronization of _cnt and _ptr (caused by an interrupt or other
48  * signal) is not immediately detected.
49  */
50 
51 Uchar _sibuf[BUFSIZ + _SMBFSZ], _sobuf[BUFSIZ + _SMBFSZ];
52 Uchar _smbuf[_NFILE + 1][_SMBFSZ] = {0};  /* shared library compatibility */
53 
54 
55 #define	DEFAULTMBSTATE \
56 	{ NULL, NULL, {0, 0, 0, 0, 0, 0, 0, 0}, 0, {0, 0}}
57 
58 #ifdef	_LP64
59 
60 #if _NFILE != 20
61 #error "_iob[] initialization impossible"
62 #endif
63 
64 FILE _iob[_NFILE] = {
65 	{ NULL, NULL, NULL, 0, 0, _IOREAD, RECURSIVEMUTEX, DEFAULTMBSTATE },
66 	{ NULL, NULL, NULL, 0, 1, _IOWRT, RECURSIVEMUTEX, DEFAULTMBSTATE },
67 	{ NULL, NULL, NULL, 0, 2, _IOWRT|_IONBF, RECURSIVEMUTEX,
68 		DEFAULTMBSTATE },
69 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
70 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
71 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
72 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
73 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
74 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
75 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
76 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
77 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
78 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
79 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
80 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
81 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
82 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
83 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
84 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
85 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE }
86 };
87 
88 #else
89 
90 #if _NFILE != 20 && _NFILE != 60
91 #error "_iob[] initialization impossible"
92 #endif
93 
94 /*
95  * FILEs not in _iob will never reference this table, so we only need _NFILE
96  * entries.
97  */
98 struct xFILEdata _xftab[_NFILE] = {
99 	XFILEINITIALIZER, XFILEINITIALIZER,
100 	{ 0, _smbuf[2] + _SBFSIZ, RECURSIVEMUTEX, DEFAULTMBSTATE }, /* stderr */
101 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
102 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
103 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
104 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
105 #if _NFILE == 60
106 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
107 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
108 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
109 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
110 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
111 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
112 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
113 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
114 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
115 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
116 #endif
117 	XFILEINITIALIZER };
118 
119 /*
120  * Ptrs to end of read/write buffers for first _NFILE devices.
121  * There is an extra bufend pointer which corresponds to the dummy
122  * file number _NFILE, which is used by sscanf and sprintf.
123  * Our implementation makes sure it never references _realbufend/_reallock/
124  * etc for *sscanf() and *sprintf(); such use of a shared item would not be
125  * thread safe.
126  */
127 Uchar *_bufendtab[_NFILE+1] = { NULL, NULL, _smbuf[2] + _SBFSIZ, };
128 
129 FILE _iob[_NFILE] = {
130 	{ 0, NULL, NULL, _IOREAD, 0 },
131 	{ 0, NULL, NULL, _IOWRT, 1 },
132 	{ 0, NULL, NULL, _IOWRT|_IONBF, 2 },
133 };
134 
135 /*
136  * Ptr to end of io control blocks
137  */
138 FILE *_lastbuf = &_iob[_NFILE];
139 
140 #endif	/*	_LP64	*/
141