xref: /titanic_50/usr/src/head/iso/stdio_iso.h (revision 91d7f85e02991954d1e1bd44673df567ad8dcc87)
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 2014 Garrett D'Amore <garrett@damore.org>
24  *
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 /*	Copyright (c) 1988 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 /*
33  * An application should not include this header directly.  Instead it
34  * should be included only through the inclusion of other Sun headers.
35  *
36  * The contents of this header is limited to identifiers specified in the
37  * C Standard.  Any new identifiers specified in future amendments to the
38  * C Standard must be placed in this header.  If these new identifiers
39  * are required to also be in the C++ Standard "std" namespace, then for
40  * anything other than macro definitions, corresponding "using" directives
41  * must also be added to <stdio.h>.
42  */
43 
44 /*
45  * User-visible pieces of the ANSI C standard I/O package.
46  */
47 
48 #ifndef _ISO_STDIO_ISO_H
49 #define	_ISO_STDIO_ISO_H
50 
51 #include <sys/feature_tests.h>
52 #include <sys/va_list.h>
53 #include <stdio_tag.h>
54 #include <stdio_impl.h>
55 
56 /*
57  * If feature test macros are set that enable interfaces that use types
58  * defined in <sys/types.h>, get those types by doing the include.
59  *
60  * Note that in asking for the interfaces associated with this feature test
61  * macro one also asks for definitions of the POSIX types.
62  */
63 
64 #ifdef	__cplusplus
65 extern "C" {
66 #endif
67 
68 #if !defined(_LP64) && (_FILE_OFFSET_BITS == 64 || defined(_LARGEFILE64_SOURCE))
69 /*
70  * The following typedefs are adopted from ones in <sys/types.h> (with leading
71  * underscores added to avoid polluting the ANSI C name space).  See the
72  * commentary there for further explanation.
73  */
74 #if defined(_LONGLONG_TYPE)
75 typedef	long long	__longlong_t;
76 #else
77 /* used to reserve space and generate alignment */
78 typedef union {
79 	double	_d;
80 	int	_l[2];
81 } __longlong_t;
82 #endif
83 #endif  /* !_LP64 && _FILE_OFFSET_BITS == 64 || defined(_LARGEFILE64_SOURCE) */
84 
85 #if __cplusplus >= 199711L
86 namespace std {
87 #endif
88 
89 #if !defined(_FILEDEFED) || __cplusplus >= 199711L
90 #define	_FILEDEFED
91 typedef	__FILE FILE;
92 #endif
93 
94 #if !defined(_SIZE_T) || __cplusplus >= 199711L
95 #define	_SIZE_T
96 #if defined(_LP64) || defined(_I32LPx)
97 typedef unsigned long	size_t;		/* size of something in bytes */
98 #else
99 typedef unsigned int	size_t;		/* (historical version) */
100 #endif
101 #endif	/* !_SIZE_T */
102 
103 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
104 typedef long		fpos_t;
105 #else
106 typedef	__longlong_t	fpos_t;
107 #endif
108 
109 #if __cplusplus >= 199711L
110 }
111 #endif /* end of namespace std */
112 
113 #ifndef	NULL
114 #if defined(_LP64)
115 #define	NULL	0L
116 #else
117 #define	NULL	0
118 #endif
119 #endif
120 
121 #define	BUFSIZ	1024
122 
123 /*
124  * The value of _NFILE is defined in the Processor Specific ABI.  The value
125  * is chosen for historical reasons rather than for truly processor related
126  * attribute.  Note that the SPARC Processor Specific ABI uses the common
127  * UNIX historical value of 20 so it is allowed to fall through.
128  */
129 #if defined(__i386)
130 #define	_NFILE	60	/* initial number of streams: Intel x86 ABI */
131 #else
132 #define	_NFILE	20	/* initial number of streams: SPARC ABI and default */
133 #endif
134 
135 #define	_SBFSIZ	8	/* compatibility with shared libs */
136 
137 #define	_IOFBF		0000	/* full buffered */
138 #define	_IOLBF		0100	/* line buffered */
139 #define	_IONBF		0004	/* not buffered */
140 #define	_IOEOF		0020	/* EOF reached on read */
141 #define	_IOERR		0040	/* I/O error from system */
142 
143 #define	_IOREAD		0001	/* currently reading */
144 #define	_IOWRT		0002	/* currently writing */
145 #define	_IORW		0200	/* opened for reading and writing */
146 #define	_IOMYBUF	0010	/* stdio malloc()'d buffer */
147 
148 #ifndef EOF
149 #define	EOF	(-1)
150 #endif
151 
152 #define	FOPEN_MAX	_NFILE
153 #define	FILENAME_MAX    1024	/* max # of characters in a path name */
154 
155 #define	SEEK_SET	0
156 #define	SEEK_CUR	1
157 #define	SEEK_END	2
158 #define	TMP_MAX		17576	/* 26 * 26 * 26 */
159 
160 #define	L_tmpnam	25	/* (sizeof(P_tmpdir) + 15) */
161 
162 extern __FILE	__iob[_NFILE];
163 #define	stdin	(&__iob[0])
164 #define	stdout	(&__iob[1])
165 #define	stderr	(&__iob[2])
166 
167 #if __cplusplus >= 199711L
168 namespace std {
169 #endif
170 
171 #if !defined(_LP64) && !defined(_LONGLONG_TYPE)
172 
173 #ifdef __PRAGMA_REDEFINE_EXTNAME
174 #pragma redefine_extname fprintf	_fprintf_c89
175 #pragma redefine_extname printf		_printf_c89
176 #pragma redefine_extname sprintf	_sprintf_c89
177 #pragma redefine_extname vfprintf	_vfprintf_c89
178 #pragma redefine_extname vprintf	_vprintf_c89
179 #pragma redefine_extname vsprintf	_vsprintf_c89
180 #pragma redefine_extname fscanf		_fscanf_c89
181 #pragma redefine_extname scanf		_scanf_c89
182 #pragma redefine_extname sscanf		_sscanf_c89
183 #else
184 #define	fprintf		_fprintf_c89
185 #define	printf		_printf_c89
186 #define	sprintf		_sprintf_c89
187 #define	vfprintf	_vfprintf_c89
188 #define	vprintf		_vprintf_c89
189 #define	vsprintf	_vsprintf_c89
190 #define	fscanf		_fscanf_c89
191 #define	scanf		_scanf_c89
192 #define	sscanf		_sscanf_c89
193 #endif
194 
195 #endif /* !defined(_LP64) && !defined(_LONGLONG_TYPE) */
196 
197 extern int	remove(const char *);
198 extern int	rename(const char *, const char *);
199 extern FILE	*tmpfile(void);
200 extern char	*tmpnam(char *);
201 extern int	fclose(FILE *);
202 extern int	fflush(FILE *);
203 extern FILE	*fopen(const char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD);
204 extern FILE	*freopen(const char *_RESTRICT_KYWD,
205 			const char *_RESTRICT_KYWD, FILE *_RESTRICT_KYWD);
206 extern void	setbuf(FILE *_RESTRICT_KYWD, char *_RESTRICT_KYWD);
207 extern int	setvbuf(FILE *_RESTRICT_KYWD, char *_RESTRICT_KYWD, int,
208 			size_t);
209 /* PRINTFLIKE2 */
210 extern int	fprintf(FILE *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, ...);
211 /* SCANFLIKE2 */
212 extern int	fscanf(FILE *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, ...);
213 /* PRINTFLIKE1 */
214 extern int	printf(const char *_RESTRICT_KYWD, ...);
215 /* SCANFLIKE1 */
216 extern int	scanf(const char *_RESTRICT_KYWD, ...);
217 /* PRINTFLIKE2 */
218 extern int	sprintf(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD, ...);
219 /* SCANFLIKE2 */
220 extern int	sscanf(const char *_RESTRICT_KYWD,
221 			const char *_RESTRICT_KYWD, ...);
222 extern int	vfprintf(FILE *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
223 			__va_list);
224 extern int	vprintf(const char *_RESTRICT_KYWD, __va_list);
225 extern int	vsprintf(char *_RESTRICT_KYWD, const char *_RESTRICT_KYWD,
226 			__va_list);
227 extern int	fgetc(FILE *);
228 extern char	*fgets(char *_RESTRICT_KYWD, int, FILE *_RESTRICT_KYWD);
229 extern int	fputc(int, FILE *);
230 extern int	fputs(const char *_RESTRICT_KYWD, FILE *_RESTRICT_KYWD);
231 #if (__cplusplus >= 199711L && (defined(_LP64) || defined(_REENTRANT))) || \
232 	__cplusplus < 199711L
233 extern int	getc(FILE *);
234 extern int	putc(int, FILE *);
235 #endif
236 #if (__cplusplus >= 199711L && defined(_REENTRANT)) || \
237 	__cplusplus < 199711L
238 extern int	getchar(void);
239 extern int	putchar(int);
240 #endif
241 extern char	*gets(char *);
242 extern int	puts(const char *);
243 extern int	ungetc(int, FILE *);
244 extern size_t	fread(void *_RESTRICT_KYWD, size_t, size_t,
245 	FILE *_RESTRICT_KYWD);
246 extern size_t	fwrite(const void *_RESTRICT_KYWD, size_t, size_t,
247 	FILE *_RESTRICT_KYWD);
248 #if !defined(__lint) || defined(_LP64) || _FILE_OFFSET_BITS == 32
249 extern int	fgetpos(FILE *_RESTRICT_KYWD, fpos_t *_RESTRICT_KYWD);
250 extern int	fsetpos(FILE *, const fpos_t *);
251 #endif
252 extern int	fseek(FILE *, long, int);
253 extern long	ftell(FILE *);
254 extern void	rewind(FILE *);
255 #if (__cplusplus >= 199711L && (defined(_LP64) || defined(_REENTRANT))) || \
256 	__cplusplus < 199711L
257 extern void	clearerr(FILE *);
258 extern int	feof(FILE *);
259 extern int	ferror(FILE *);
260 #endif
261 extern void	perror(const char *);
262 
263 #ifndef	_LP64
264 extern int	__filbuf(FILE *);
265 extern int	__flsbuf(int, FILE *);
266 #endif	/*	_LP64	*/
267 
268 #if __cplusplus >= 199711L
269 }
270 #endif /* end of namespace std */
271 
272 #if !defined(__lint)
273 
274 #if	!defined(_REENTRANT) && !defined(_LP64)
275 
276 #if __cplusplus >= 199711L
277 namespace std {
278 inline int getc(FILE *_p) {
279 	return (--_p->_cnt < 0 ? __filbuf(_p) : (int)*_p->_ptr++); }
280 inline int putc(int _x, FILE *_p) {
281 	return (--_p->_cnt < 0 ? __flsbuf(_x, _p)
282 		: (int)(*_p->_ptr++ = (unsigned char) _x)); }
283 }
284 #else /* __cplusplus >= 199711L */
285 #define	getc(p)		(--(p)->_cnt < 0 ? __filbuf(p) : (int)*(p)->_ptr++)
286 #define	putc(x, p)	(--(p)->_cnt < 0 ? __flsbuf((x), (p)) \
287 				: (int)(*(p)->_ptr++ = (unsigned char) (x)))
288 #endif /* __cplusplus >= 199711L */
289 
290 #endif /* !defined(_REENTRANT) && !defined(_LP64) */
291 
292 #ifndef	_REENTRANT
293 
294 #if __cplusplus >= 199711L
295 namespace std {
296 inline int getchar() { return getc(stdin); }
297 inline int putchar(int _x) { return putc(_x, stdout); }
298 }
299 #else
300 #define	getchar()	getc(stdin)
301 #define	putchar(x)	putc((x), stdout)
302 #endif /* __cplusplus >= 199711L */
303 
304 #ifndef	_LP64
305 #if __cplusplus >= 199711L
306 namespace std {
307 inline void clearerr(FILE *_p) { _p->_flag &= ~(_IOERR | _IOEOF); }
308 inline int feof(FILE *_p) { return _p->_flag & _IOEOF; }
309 inline int ferror(FILE *_p) { return _p->_flag & _IOERR; }
310 }
311 #else /* __cplusplus >= 199711L */
312 #define	clearerr(p)	((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
313 #define	feof(p)		((p)->_flag & _IOEOF)
314 #define	ferror(p)	((p)->_flag & _IOERR)
315 #endif /* __cplusplus >= 199711L */
316 #endif	/* _LP64 */
317 
318 #endif	/* _REENTRANT */
319 
320 #endif	/* !defined(__lint) */
321 
322 #ifdef	__cplusplus
323 }
324 #endif
325 
326 #endif	/* _ISO_STDIO_ISO_H */
327