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.
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.
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]
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * User-visible pieces of the ANSI C standard I/O package.
37 #include <sys/feature_tests.h>
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.
48 #if defined(__PRAGMA_REDEFINE_EXTNAME)
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 */
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) */
76 #endif /* __PRAGMA_REDEFINE_EXTNAME */
82 #include <iso/stdio_iso.h>
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.
88 * Note that in asking for the interfaces associated with this feature test
89 * macro one also asks for definitions of the POSIX types.
93 * Allow global visibility for symbols defined in
94 * C++ "std" namespace in <iso/stdio_iso.h>.
96 #if __cplusplus >= 199711L
145 #endif /* __cplusplus >= 199711L */
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.
151 #include <iso/stdio_c99.h>
157 #if defined(_LARGEFILE_SOURCE) || defined(_XPG5)
160 #if defined(_LP64) || _FILE_OFFSET_BITS == 32
163 typedef __longlong_t off_t
;
165 #ifdef _LARGEFILE64_SOURCE
167 typedef off_t off64_t
;
169 typedef __longlong_t off64_t
;
171 #endif /* _LARGEFILE64_SOURCE */
173 #endif /* _LARGEFILE_SOURCE */
175 #ifdef _LARGEFILE64_SOURCE
177 typedef fpos_t fpos64_t
;
179 typedef __longlong_t fpos64_t
;
181 #endif /* _LARGEFILE64_SOURCE */
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.
188 #if defined(_XPG4) && !defined(_VA_LIST)
190 typedef __va_list
va_list;
191 #endif /* defined(_XPG4 && !defined(_VA_LIST) */
193 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
194 defined(__XOPEN_OR_POSIX)
198 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
199 #if !defined(_XPG6) || defined(__EXTENSIONS__)
203 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
205 #if defined(__EXTENSIONS__) || \
206 (!defined(_STRICT_STDC) && !defined(_POSIX_C_SOURCE)) || \
207 defined(_XOPEN_SOURCE)
209 #define P_tmpdir "/var/tmp/"
210 #endif /* defined(__EXTENSIONS__) || (!defined(_STRICT_STDC) ... */
212 #ifndef _STDIO_ALLOCATE
213 extern unsigned char _sibuf
[], _sobuf
[];
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
233 #endif /* !__PRAGMA_REDEFINE_EXTNAME */
234 #endif /* !_LP64 && _FILE_OFFSET_BITS == 64 */
237 extern unsigned char *_bufendtab
[];
238 extern FILE *_lastbuf
;
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
253 #endif /* !__PRAGMA_REDEFINE_EXTNAME */
254 #endif /* _LP64 && _LARGEFILE64_SOURCE */
258 #if defined(_LP64) || defined(_I32LPx)
259 typedef long ssize_t
; /* size of something in bytes or -1 */
261 typedef int ssize_t
; /* (historical version) */
263 #endif /* !_SSIZE_T */
265 extern char *tmpnam_r(char *);
267 #if defined(__EXTENSIONS__) || \
268 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
269 extern int fcloseall(void);
270 extern void setbuffer(FILE *, char *, size_t);
271 extern int setlinebuf(FILE *);
273 extern int asprintf(char **, const char *, ...);
275 extern int vasprintf(char **, const char *, __va_list
);
278 #if defined(__EXTENSIONS__) || \
279 (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX))
280 /* || defined(_XPG7) */
281 extern ssize_t
getdelim(char **_RESTRICT_KYWD
, size_t *_RESTRICT_KYWD
,
282 int, FILE *_RESTRICT_KYWD
);
283 extern ssize_t
getline(char **_RESTRICT_KYWD
, size_t *_RESTRICT_KYWD
,
284 FILE *_RESTRICT_KYWD
);
285 #endif /* __EXTENSIONS__ ... */
288 * The following are known to POSIX and XOPEN, but not to ANSI-C.
290 #if defined(__EXTENSIONS__) || \
291 !defined(_STRICT_STDC) || defined(__XOPEN_OR_POSIX)
293 extern FILE *fdopen(int, const char *);
294 extern char *ctermid(char *);
295 extern int fileno(FILE *);
297 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
300 * The following are known to POSIX.1c, but not to ANSI-C or XOPEN.
302 extern void flockfile(FILE *);
303 extern int ftrylockfile(FILE *);
304 extern void funlockfile(FILE *);
305 extern int getc_unlocked(FILE *);
306 extern int getchar_unlocked(void);
307 extern int putc_unlocked(int, FILE *);
308 extern int putchar_unlocked(int);
311 * The following are known to XOPEN, but not to ANSI-C or POSIX.
313 #if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
314 defined(_XOPEN_SOURCE)
315 extern FILE *popen(const char *, const char *);
316 extern char *tempnam(const char *, const char *);
317 extern int pclose(FILE *);
318 #if !defined(_XOPEN_SOURCE)
319 extern int getsubopt(char **, char *const *, char **);
320 #endif /* !defined(_XOPEN_SOURCE) */
322 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
323 #if !defined(_XPG6) || defined(__EXTENSIONS__)
324 extern char *cuserid(char *);
325 extern int getopt(int, char *const *, const char *);
327 extern int optind
, opterr
, optopt
;
328 extern int getw(FILE *);
329 extern int putw(int, FILE *);
330 #endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
332 #endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */
335 * The following are defined as part of the Large File Summit interfaces.
337 #if defined(_LARGEFILE_SOURCE) || defined(_XPG5)
338 extern int fseeko(FILE *, off_t
, int);
339 extern off_t
ftello(FILE *);
343 * The following are defined as part of the transitional Large File Summit
346 #if defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
347 !defined(__PRAGMA_REDEFINE_EXTNAME))
348 extern FILE *fopen64(const char *, const char *);
349 extern FILE *freopen64(const char *, const char *, FILE *);
350 extern FILE *tmpfile64(void);
351 extern int fgetpos64(FILE *, fpos64_t
*);
352 extern int fsetpos64(FILE *, const fpos64_t
*);
353 extern int fseeko64(FILE *, off64_t
, int);
354 extern off64_t
ftello64(FILE *);
358 #define getc_unlocked(p) (--(p)->_cnt < 0 \
361 #define putc_unlocked(x, p) (--(p)->_cnt < 0 \
362 ? __flsbuf((x), (p)) \
363 : (int)(*(p)->_ptr++ = \
364 (unsigned char) (x)))
366 #define getchar_unlocked() getc_unlocked(stdin)
367 #define putchar_unlocked(x) putc_unlocked((x), stdout)
373 #endif /* _STDIO_H */