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