xref: /illumos-gate/usr/src/lib/libc/port/stdio/data.c (revision 66582b606a8194f7f3ba5b3a3a6dca5b0d346361)
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 /*
31  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
32  * Use is subject to license terms.
33  */
34 
35 #pragma weak __iob = _iob
36 
37 #include "lint.h"
38 #include "mbstatet.h"
39 #include "mtlib.h"
40 #include "file64.h"
41 #include <stdio.h>
42 #include <thread.h>
43 #include <synch.h>
44 #include "stdiom.h"
45 #include <wchar.h>
46 
47 /*
48  * Ptrs to start of preallocated buffers for stdin, stdout.
49  * Some slop is allowed at the end of the buffers in case an upset in
50  * the synchronization of _cnt and _ptr (caused by an interrupt or other
51  * signal) is not immediately detected.
52  */
53 
54 Uchar _sibuf[BUFSIZ + _SMBFSZ], _sobuf[BUFSIZ + _SMBFSZ];
55 Uchar _smbuf[_NFILE + 1][_SMBFSZ] = {0};  /* shared library compatibility */
56 
57 
58 #define	DEFAULTMBSTATE \
59 	{ 0 }
60 
61 #ifdef	_LP64
62 
63 #if _NFILE != 20
64 #error "_iob[] initialization impossible"
65 #endif
66 
67 FILE _iob[_NFILE] = {
68 	{ NULL, NULL, NULL, 0, 0, _IOREAD, RECURSIVEMUTEX, DEFAULTMBSTATE },
69 	{ NULL, NULL, NULL, 0, 1, _IOWRT, RECURSIVEMUTEX, DEFAULTMBSTATE },
70 	{ NULL, NULL, NULL, 0, 2, _IOWRT|_IONBF, RECURSIVEMUTEX,
71 		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 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE },
88 	{ NULL, NULL, NULL, 0, 0, 0, RECURSIVEMUTEX, DEFAULTMBSTATE }
89 };
90 
91 #else
92 
93 #if _NFILE != 20 && _NFILE != 60
94 #error "_iob[] initialization impossible"
95 #endif
96 
97 /*
98  * FILEs not in _iob will never reference this table, so we only need _NFILE
99  * entries.
100  */
101 struct xFILEdata _xftab[_NFILE] = {
102 	XFILEINITIALIZER, XFILEINITIALIZER,
103 	{ 0, _smbuf[2] + _SBFSIZ, RECURSIVEMUTEX, DEFAULTMBSTATE }, /* stderr */
104 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
105 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
106 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
107 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
108 #if _NFILE == 60
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 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
118 	XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER, XFILEINITIALIZER,
119 #endif
120 	XFILEINITIALIZER };
121 
122 /*
123  * Ptrs to end of read/write buffers for first _NFILE devices.
124  * There is an extra bufend pointer which corresponds to the dummy
125  * file number _NFILE, which is used by sscanf and sprintf.
126  * Our implementation makes sure it never references _realbufend/_reallock/
127  * etc for *sscanf() and *sprintf(); such use of a shared item would not be
128  * thread safe.
129  */
130 Uchar *_bufendtab[_NFILE+1] = { NULL, NULL, _smbuf[2] + _SBFSIZ, };
131 
132 FILE _iob[_NFILE] = {
133 	{ 0, NULL, NULL, _IOREAD, 0 },
134 	{ 0, NULL, NULL, _IOWRT, 1 },
135 	{ 0, NULL, NULL, _IOWRT|_IONBF, 2 },
136 };
137 
138 /*
139  * Ptr to end of io control blocks
140  */
141 FILE *_lastbuf = &_iob[_NFILE];
142 
143 #endif	/*	_LP64	*/
144