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