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