xref: /illumos-gate/usr/src/head/stdio.h (revision ef9416a894c90df5d46b888dbe2908c7f00fd409)
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 2014 Garrett D'Amore <garrett@damore.org>
24  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
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 extern FILE	*fopen64(const char *, const char *);
220 extern FILE	*freopen64(const char *, const char *, FILE *);
221 extern FILE	*tmpfile64(void);
222 extern int	fgetpos64(FILE *, fpos_t *);
223 extern int	fsetpos64(FILE *, const fpos_t *);
224 #define	fopen			fopen64
225 #define	freopen			freopen64
226 #define	tmpfile			tmpfile64
227 #define	fgetpos			fgetpos64
228 #define	fsetpos			fsetpos64
229 #ifdef	_LARGEFILE_SOURCE
230 #define	fseeko			fseeko64
231 #define	ftello			ftello64
232 #endif
233 #endif	/* !__PRAGMA_REDEFINE_EXTNAME */
234 #endif	/* !_LP64 && _FILE_OFFSET_BITS == 64 */
235 
236 #ifndef _LP64
237 extern unsigned char	*_bufendtab[];
238 extern FILE		*_lastbuf;
239 #endif
240 
241 /* In the LP64 compilation environment, all APIs are already large file */
242 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
243 #if !defined(__PRAGMA_REDEFINE_EXTNAME)
244 #define	fopen64		fopen
245 #define	freopen64	freopen
246 #define	tmpfile64	tmpfile
247 #define	fgetpos64	fgetpos
248 #define	fsetpos64	fsetpos
249 #ifdef	_LARGEFILE_SOURCE
250 #define	fseeko64	fseeko
251 #define	ftello64	ftello
252 #endif
253 #endif	/* !__PRAGMA_REDEFINE_EXTNAME */
254 #endif	/* _LP64 && _LARGEFILE64_SOURCE */
255 
256 #ifndef	_SSIZE_T
257 #define	_SSIZE_T
258 #if defined(_LP64) || defined(_I32LPx)
259 typedef long	ssize_t;	/* size of something in bytes or -1 */
260 #else
261 typedef int	ssize_t;	/* (historical version) */
262 #endif
263 #endif	/* !_SSIZE_T */
264 
265 #if defined(__EXTENSIONS__) || \
266 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
267 	defined(_REENTRANT)
268 extern char	*tmpnam_r(char *);
269 #endif
270 
271 #if defined(__EXTENSIONS__) || \
272 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
273 extern int fcloseall(void);
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 #if defined(__EXTENSIONS__) || \
283 	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
284 	/* || defined(_XPG7) */
285 extern ssize_t getdelim(char **_RESTRICT_KYWD, size_t *_RESTRICT_KYWD,
286 	int, FILE *_RESTRICT_KYWD);
287 extern ssize_t getline(char **_RESTRICT_KYWD, size_t *_RESTRICT_KYWD,
288 	FILE *_RESTRICT_KYWD);
289 #endif	/* __EXTENSIONS__ ... */
290 
291 /*
292  * The following are known to POSIX and XOPEN, but not to ANSI-C.
293  */
294 #if defined(__EXTENSIONS__) || \
295 	!defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)
296 
297 extern FILE	*fdopen(int, const char *);
298 extern char	*ctermid(char *);
299 extern int	fileno(FILE *);
300 
301 #endif	/* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
302 
303 /*
304  * The following are known to POSIX.1c, but not to ANSI-C or XOPEN.
305  */
306 #if defined(__EXTENSIONS__) || defined(_REENTRANT) || \
307 	(_POSIX_C_SOURCE - 0 >= 199506L)
308 extern void	flockfile(FILE *);
309 extern int	ftrylockfile(FILE *);
310 extern void	funlockfile(FILE *);
311 extern int	getc_unlocked(FILE *);
312 extern int	getchar_unlocked(void);
313 extern int	putc_unlocked(int, FILE *);
314 extern int	putchar_unlocked(int);
315 
316 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT).. */
317 
318 /*
319  * The following are known to XOPEN, but not to ANSI-C or POSIX.
320  */
321 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
322 	defined(_XOPEN_SOURCE)
323 extern FILE	*popen(const char *, const char *);
324 extern char	*tempnam(const char *, const char *);
325 extern int	pclose(FILE *);
326 #if !defined(_XOPEN_SOURCE)
327 extern int	getsubopt(char **, char *const *, char **);
328 #endif /* !defined(_XOPEN_SOURCE) */
329 
330 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
331 #if !defined(_XPG6) || defined(__EXTENSIONS__)
332 extern char	*cuserid(char *);
333 extern int	getopt(int, char *const *, const char *);
334 extern char	*optarg;
335 extern int	optind, opterr, optopt;
336 extern int	getw(FILE *);
337 extern int	putw(int, FILE *);
338 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
339 
340 #endif	/* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
341 
342 /*
343  * The following are defined as part of the Large File Summit interfaces.
344  */
345 #if defined(_LARGEFILE_SOURCE) || defined(_XPG5)
346 extern int	fseeko(FILE *, off_t, int);
347 extern off_t	ftello(FILE *);
348 #endif
349 
350 /*
351  * The following are defined as part of the transitional Large File Summit
352  * interfaces.
353  */
354 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
355 	    !defined(__PRAGMA_REDEFINE_EXTNAME))
356 extern FILE	*fopen64(const char *, const char *);
357 extern FILE	*freopen64(const char *, const char *, FILE *);
358 extern FILE	*tmpfile64(void);
359 extern int	fgetpos64(FILE *, fpos64_t *);
360 extern int	fsetpos64(FILE *, const fpos64_t *);
361 extern int	fseeko64(FILE *, off64_t, int);
362 extern off64_t	ftello64(FILE *);
363 #endif
364 
365 /*
366  * XPG7 symbols
367  */
368 #if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
369 extern FILE	*fmemopen(void *_RESTRICT_KYWD, size_t,
370 		    const char *_RESTRICT_KYWD);
371 extern FILE	*open_memstream(char **, size_t *);
372 #endif	/* !_STRICT_SYMBOLS || _XPG7 */
373 
374 #if defined(__EXTENSIONS__) || defined(_REENTRANT) || \
375 	    (_POSIX_C_SOURCE - 0 >= 199506L)
376 #define	getchar_unlocked()	getc_unlocked(stdin)
377 #define	putchar_unlocked(x)	putc_unlocked((x), stdout)
378 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT).. */
379 
380 #ifdef	__cplusplus
381 }
382 #endif
383 
384 #endif	/* _STDIO_H */
385