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
40extern "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
97using std::FILE;
98using std::size_t;
99using std::fpos_t;
100using std::remove;
101using std::rename;
102using std::tmpfile;
103using std::tmpnam;
104using std::fclose;
105using std::fflush;
106using std::fopen;
107using std::freopen;
108using std::setbuf;
109using std::setvbuf;
110using std::fprintf;
111using std::fscanf;
112using std::printf;
113using std::scanf;
114using std::sprintf;
115using std::sscanf;
116using std::vfprintf;
117using std::vprintf;
118using std::vsprintf;
119using std::fgetc;
120using std::fgets;
121using std::fputc;
122using std::fputs;
123using std::getc;
124using std::getchar;
125using std::gets;
126using std::putc;
127using std::putchar;
128using std::puts;
129using std::ungetc;
130using std::fread;
131using std::fwrite;
132using std::fgetpos;
133using std::fseek;
134using std::fsetpos;
135using std::ftell;
136using std::rewind;
137using std::clearerr;
138using std::feof;
139using std::ferror;
140using std::perror;
141#ifndef	_LP64
142using std::__filbuf;
143using 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
154extern "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
161typedef long		off_t;
162#else
163typedef __longlong_t	off_t;
164#endif
165#ifdef	_LARGEFILE64_SOURCE
166#ifdef _LP64
167typedef	off_t		off64_t;
168#else
169typedef __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
177typedef fpos_t		fpos64_t;
178#else
179typedef __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
190typedef	__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
213extern 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)
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#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
237extern unsigned char	*_bufendtab[];
238extern 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)
259typedef long	ssize_t;	/* size of something in bytes or -1 */
260#else
261typedef 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)
268extern char	*tmpnam_r(char *);
269#endif
270
271#if defined(__EXTENSIONS__) || \
272	(!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
273extern int fcloseall(void);
274extern void setbuffer(FILE *, char *, size_t);
275extern int setlinebuf(FILE *);
276/* PRINTFLIKE2 */
277extern int asprintf(char **, const char *, ...);
278/* PRINTFLIKE2 */
279extern 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) */
285extern ssize_t getdelim(char **_RESTRICT_KYWD, size_t *_RESTRICT_KYWD,
286	int, FILE *_RESTRICT_KYWD);
287extern 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
297extern FILE	*fdopen(int, const char *);
298extern char	*ctermid(char *);
299extern 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)
308extern void	flockfile(FILE *);
309extern int	ftrylockfile(FILE *);
310extern void	funlockfile(FILE *);
311extern int	getc_unlocked(FILE *);
312extern int	getchar_unlocked(void);
313extern int	putc_unlocked(int, FILE *);
314extern 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)
323extern FILE	*popen(const char *, const char *);
324extern char	*tempnam(const char *, const char *);
325extern int	pclose(FILE *);
326#if !defined(_XOPEN_SOURCE)
327extern 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__)
332extern char	*cuserid(char *);
333extern int	getopt(int, char *const *, const char *);
334extern char	*optarg;
335extern int	optind, opterr, optopt;
336extern int	getw(FILE *);
337extern 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)
346extern int	fseeko(FILE *, off_t, int);
347extern 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))
356extern FILE	*fopen64(const char *, const char *);
357extern FILE	*freopen64(const char *, const char *, FILE *);
358extern FILE	*tmpfile64(void);
359extern int	fgetpos64(FILE *, fpos64_t *);
360extern int	fsetpos64(FILE *, const fpos64_t *);
361extern int	fseeko64(FILE *, off64_t, int);
362extern off64_t	ftello64(FILE *);
363#endif
364
365/*
366 * XPG7 symbols
367 */
368#if !defined(_STRICT_SYMBOLS) || defined(_XPG7)
369extern FILE	*fmemopen(void *_RESTRICT_KYWD, size_t,
370		    const char *_RESTRICT_KYWD);
371extern 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