xref: /titanic_50/usr/src/head/stdio.h (revision 0f509175c7fa701d6edf3f65789303587905b1bd)
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  * User-visible pieces of the ANSI C standard I/O package.
33  */
34 
35 #ifndef _STDIO_H
36 #define	_STDIO_H
37 
38 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 2.34.1.2 */
39 
40 #include <sys/feature_tests.h>
41 
42 #ifdef	__cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Do all of our 'redefine_extname' processing before
48  * declarations of the associated functions are seen.
49  * This is necessary to keep gcc happy.
50  */
51 #if defined(__PRAGMA_REDEFINE_EXTNAME)
52 
53 /* large file compilation environment setup */
54 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
55 #pragma redefine_extname	fopen		fopen64
56 #pragma redefine_extname	freopen		freopen64
57 #pragma redefine_extname	tmpfile		tmpfile64
58 #pragma redefine_extname	fgetpos		fgetpos64
59 #pragma redefine_extname	fsetpos		fsetpos64
60 #if defined(_LARGEFILE_SOURCE)
61 #pragma redefine_extname	fseeko		fseeko64
62 #pragma redefine_extname	ftello		ftello64
63 #endif	/* _LARGEFILE_SOURCE */
64 #endif	/* !defined(_LP64) && _FILE_OFFSET_BITS == 64 */
65 
66 /* In the LP64 compilation environment, all APIs are already large file */
67 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
68 #pragma redefine_extname	fopen64		fopen
69 #pragma redefine_extname	freopen64	freopen
70 #pragma redefine_extname	tmpfile64	tmpfile
71 #pragma redefine_extname	fgetpos64	fgetpos
72 #pragma redefine_extname	fsetpos64	fsetpos
73 #if defined(_LARGEFILE_SOURCE)
74 #pragma redefine_extname	fseeko64	fseeko
75 #pragma redefine_extname	ftello64	ftello
76 #endif	/* _LARGEFILE_SOURCE */
77 #endif	/* defined(_LP64) && defined(_LARGEFILE64_SOURCE) */
78 
79 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
80 
81 #ifdef	__cplusplus
82 }
83 #endif
84 
85 #include <iso/stdio_iso.h>
86 
87 /*
88  * If feature test macros are set that enable interfaces that use types
89  * defined in <sys/types.h>, get those types by doing the include.
90  *
91  * Note that in asking for the interfaces associated with this feature test
92  * macro one also asks for definitions of the POSIX types.
93  */
94 
95 /*
96  * Allow global visibility for symbols defined in
97  * C++ "std" namespace in <iso/stdio_iso.h>.
98  */
99 #if __cplusplus >= 199711L
100 using std::FILE;
101 using std::size_t;
102 using std::fpos_t;
103 using std::remove;
104 using std::rename;
105 using std::tmpfile;
106 using std::tmpnam;
107 using std::fclose;
108 using std::fflush;
109 using std::fopen;
110 using std::freopen;
111 using std::setbuf;
112 using std::setvbuf;
113 using std::fprintf;
114 using std::fscanf;
115 using std::printf;
116 using std::scanf;
117 using std::sprintf;
118 using std::sscanf;
119 using std::vfprintf;
120 using std::vprintf;
121 using std::vsprintf;
122 using std::fgetc;
123 using std::fgets;
124 using std::fputc;
125 using std::fputs;
126 using std::getc;
127 using std::getchar;
128 using std::gets;
129 using std::putc;
130 using std::putchar;
131 using std::puts;
132 using std::ungetc;
133 using std::fread;
134 using std::fwrite;
135 using std::fgetpos;
136 using std::fseek;
137 using std::fsetpos;
138 using std::ftell;
139 using std::rewind;
140 using std::clearerr;
141 using std::feof;
142 using std::ferror;
143 using std::perror;
144 #ifndef	_LP64
145 using std::__filbuf;
146 using std::__flsbuf;
147 #endif	/* _LP64 */
148 #endif	/*  __cplusplus >= 199711L */
149 
150 /*
151  * This header needs to be included here because it relies on the global
152  * visibility of FILE and size_t in the C++ environment.
153  */
154 #include <iso/stdio_c99.h>
155 
156 #ifdef	__cplusplus
157 extern "C" {
158 #endif
159 
160 #if defined(_LARGEFILE_SOURCE) || defined(_XPG5)
161 #ifndef	_OFF_T
162 #define	_OFF_T
163 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
164 typedef long		off_t;
165 #else
166 typedef __longlong_t	off_t;
167 #endif
168 #ifdef	_LARGEFILE64_SOURCE
169 #ifdef _LP64
170 typedef	off_t		off64_t;
171 #else
172 typedef __longlong_t	off64_t;
173 #endif
174 #endif /* _LARGEFILE64_SOURCE */
175 #endif /* _OFF_T */
176 #endif /* _LARGEFILE_SOURCE */
177 
178 #ifdef _LARGEFILE64_SOURCE
179 #ifdef _LP64
180 typedef fpos_t		fpos64_t;
181 #else
182 typedef __longlong_t	fpos64_t;
183 #endif
184 #endif /* _LARGEFILE64_SOURCE */
185 
186 /*
187  * XPG4 requires that va_list be defined in <stdio.h> "as described in
188  * <stdarg.h>".  ANSI-C and POSIX require that the namespace of <stdio.h>
189  * not be polluted with this name.
190  */
191 #if defined(_XPG4) && !defined(_VA_LIST)
192 #define	_VA_LIST
193 typedef	__va_list va_list;
194 #endif	/* defined(_XPG4 && !defined(_VA_LIST) */
195 
196 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
197 		defined(__XOPEN_OR_POSIX)
198 
199 #define	L_ctermid	9
200 
201 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
202 #if !defined(_XPG6) || defined(__EXTENSIONS__)
203 #define	L_cuserid	9
204 #endif
205 
206 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
207 
208 #if defined(__EXTENSIONS__) || \
209 	(!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
210 	defined(_XOPEN_SOURCE)
211 
212 #define	P_tmpdir	"/var/tmp/"
213 #endif /* defined(__EXTENSIONS__) || (!defined(_STRICT_STDC) ... */
214 
215 #ifndef _STDIO_ALLOCATE
216 extern unsigned char	 _sibuf[], _sobuf[];
217 #endif
218 
219 /* large file compilation environment setup */
220 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
221 #if !defined(__PRAGMA_REDEFINE_EXTNAME)
222 #if defined(__STDC__)
223 extern FILE	*fopen64(const char *, const char *);
224 extern FILE	*freopen64(const char *, const char *, FILE *);
225 extern FILE	*tmpfile64(void);
226 extern int	fgetpos64(FILE *, fpos_t *);
227 extern int	fsetpos64(FILE *, const fpos_t *);
228 #else	/* defined(__STDC__) */
229 extern FILE	*fopen64();
230 extern FILE	*freopen64();
231 extern FILE	*tmpfile64();
232 extern int	fgetpos64();
233 extern int	fsetpos64();
234 #endif	/* defined(__STDC__) */
235 #define	fopen			fopen64
236 #define	freopen			freopen64
237 #define	tmpfile			tmpfile64
238 #define	fgetpos			fgetpos64
239 #define	fsetpos			fsetpos64
240 #ifdef	_LARGEFILE_SOURCE
241 #define	fseeko			fseeko64
242 #define	ftello			ftello64
243 #endif
244 #endif	/* !__PRAGMA_REDEFINE_EXTNAME */
245 #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
246 
247 #ifndef _LP64
248 extern unsigned char	*_bufendtab[];
249 extern FILE		*_lastbuf;
250 #endif
251 
252 /* In the LP64 compilation environment, all APIs are already large file */
253 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
254 #if !defined(__PRAGMA_REDEFINE_EXTNAME)
255 #define	fopen64		fopen
256 #define	freopen64	freopen
257 #define	tmpfile64	tmpfile
258 #define	fgetpos64	fgetpos
259 #define	fsetpos64	fsetpos
260 #ifdef	_LARGEFILE_SOURCE
261 #define	fseeko64	fseeko
262 #define	ftello64	ftello
263 #endif
264 #endif	/* !__PRAGMA_REDEFINE_EXTNAME */
265 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
266 
267 #if defined(__STDC__)
268 
269 #if defined(__EXTENSIONS__) || \
270 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
271 	defined(_REENTRANT)
272 extern char	*tmpnam_r(char *);
273 #endif
274 
275 #if defined(__EXTENSIONS__) || \
276 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
277 extern void setbuffer(FILE *, char *, size_t);
278 extern int setlinebuf(FILE *);
279 #endif
280 
281 /*
282  * The following are known to POSIX and XOPEN, but not to ANSI-C.
283  */
284 #if defined(__EXTENSIONS__) || \
285 	!defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)
286 
287 extern FILE	*fdopen(int, const char *);
288 extern char	*ctermid(char *);
289 extern int	fileno(FILE *);
290 
291 #endif	/* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
292 
293 /*
294  * The following are known to POSIX.1c, but not to ANSI-C or XOPEN.
295  */
296 #if defined(__EXTENSIONS__) || defined(_REENTRANT) || \
297 	(_POSIX_C_SOURCE - 0 >= 199506L)
298 extern void	flockfile(FILE *);
299 extern int	ftrylockfile(FILE *);
300 extern void	funlockfile(FILE *);
301 extern int	getc_unlocked(FILE *);
302 extern int	getchar_unlocked(void);
303 extern int	putc_unlocked(int, FILE *);
304 extern int	putchar_unlocked(int);
305 
306 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT).. */
307 
308 /*
309  * The following are known to XOPEN, but not to ANSI-C or POSIX.
310  */
311 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
312 	defined(_XOPEN_SOURCE)
313 extern FILE	*popen(const char *, const char *);
314 extern char	*tempnam(const char *, const char *);
315 extern int	pclose(FILE *);
316 #if !defined(_XOPEN_SOURCE)
317 extern int	getsubopt(char **, char *const *, char **);
318 #endif /* !defined(_XOPEN_SOURCE) */
319 
320 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
321 #if !defined(_XPG6) || defined(__EXTENSIONS__)
322 extern char	*cuserid(char *);
323 extern int	getopt(int, char *const *, const char *);
324 extern char	*optarg;
325 extern int	optind, opterr, optopt;
326 extern int	getw(FILE *);
327 extern int	putw(int, FILE *);
328 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
329 
330 #endif	/* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
331 
332 /*
333  * The following are defined as part of the Large File Summit interfaces.
334  */
335 #if	defined(_LARGEFILE_SOURCE) || defined(_XPG5)
336 extern int	fseeko(FILE *, off_t, int);
337 extern off_t	ftello(FILE *);
338 #endif
339 
340 /*
341  * The following are defined as part of the transitional Large File Summit
342  * interfaces.
343  */
344 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
345 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
346 extern FILE	*fopen64(const char *, const char *);
347 extern FILE	*freopen64(const char *, const char *, FILE *);
348 extern FILE	*tmpfile64(void);
349 extern int	fgetpos64(FILE *, fpos64_t *);
350 extern int	fsetpos64(FILE *, const fpos64_t *);
351 extern int	fseeko64(FILE *, off64_t, int);
352 extern off64_t	ftello64(FILE *);
353 #endif
354 
355 #else	/* !defined __STDC__ */
356 
357 #ifndef	_LP64
358 #define	_bufend(p)	((fileno(p) < _NFILE) ? _bufendtab[fileno(p)] : \
359 			(unsigned char *)_realbufend(p))
360 #define	_bufsiz(p)	(_bufend(p) - (p)->_base)
361 #endif	/*	_LP64	*/
362 
363 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \
364 	defined(_REENTRANT)
365 extern char	*tmpnam_r();
366 #endif
367 
368 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
369 extern void setbuffer();
370 extern int setlinebuf();
371 #endif
372 
373 #if defined(__EXTENSIONS__) || defined(__XOPEN_OR_POSIX)
374 extern FILE	*fdopen();
375 extern char	*ctermid();
376 extern int	fileno();
377 #endif	/* defined(__EXTENSIONS__) || defined(__XOPEN_OR_POSIX) */
378 
379 #if	defined(__EXTENSIONS__) || defined(_REENTRANT) || \
380 	    (_POSIX_C_SOURCE - 0 >= 199506L)
381 extern void	flockfile();
382 extern int	ftrylockfile();
383 extern void	funlockfile();
384 extern int	getc_unlocked();
385 extern int	getchar_unlocked();
386 extern int	putc_unlocked();
387 extern int	putchar_unlocked();
388 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT).. */
389 
390 #if defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE)
391 extern FILE	*popen();
392 extern char	*tempnam();
393 extern int	pclose();
394 
395 #if !defined(_XOPEN_SOURCE)
396 extern int	getsubopt();
397 #endif /* !defined(_XOPEN_SOURCE) */
398 
399 #if !defined(_XPG6) || defined(__EXTENSIONS__)
400 extern char	*cuserid();
401 extern int	getopt();
402 extern char	*optarg;
403 extern int	optind, opterr, optopt;
404 extern int	getw();
405 extern int	putw();
406 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
407 
408 #endif	/* defined(__EXTENSIONS__) || defined(_XOPEN_SOURCE) */
409 
410 #if	defined(_LARGEFILE_SOURCE) || defined(_XPG5)
411 extern int	fseeko();
412 extern off_t	ftello();
413 #endif
414 
415 #if	defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
416 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
417 extern FILE	*fopen64();
418 extern FILE	*freopen64();
419 extern FILE	*tmpfile64();
420 extern int	fgetpos64();
421 extern int	fsetpos64();
422 extern int	fseeko64();
423 extern off64_t	ftello64();
424 #endif
425 
426 #endif	/* __STDC__ */
427 
428 #if !defined(__lint)
429 
430 #if	defined(__EXTENSIONS__) || defined(_REENTRANT) || \
431 	    (_POSIX_C_SOURCE - 0 >= 199506L)
432 #ifndef	_LP64
433 #ifdef	__STDC__
434 #define	getc_unlocked(p)	(--(p)->_cnt < 0 \
435 					? __filbuf(p) \
436 					: (int)*(p)->_ptr++)
437 #define	putc_unlocked(x, p)	(--(p)->_cnt < 0 \
438 					? __flsbuf((x), (p)) \
439 					: (int)(*(p)->_ptr++ = \
440 					(unsigned char) (x)))
441 #else
442 #define	getc_unlocked(p)	(--(p)->_cnt < 0 \
443 					? _filbuf(p) \
444 					: (int)*(p)->_ptr++)
445 #define	putc_unlocked(x, p)	(--(p)->_cnt < 0 \
446 					? _flsbuf((x), (p)) \
447 					: (int)(*(p)->_ptr++ = \
448 					(unsigned char) (x)))
449 #endif	/* __STDC__ */
450 #endif	/* _LP64 */
451 #define	getchar_unlocked()	getc_unlocked(stdin)
452 #define	putchar_unlocked(x)	putc_unlocked((x), stdout)
453 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT).. */
454 
455 #endif	/* !defined(__lint) */
456 
457 #ifdef	__cplusplus
458 }
459 #endif
460 
461 #endif	/* _STDIO_H */
462