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