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