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
  39 extern "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
  96 using std::FILE;
  97 using std::size_t;
  98 using std::fpos_t;
  99 using std::remove;
 100 using std::rename;
 101 using std::tmpfile;
 102 using std::tmpnam;
 103 using std::fclose;
 104 using std::fflush;
 105 using std::fopen;
 106 using std::freopen;
 107 using std::setbuf;
 108 using std::setvbuf;
 109 using std::fprintf;
 110 using std::fscanf;
 111 using std::printf;
 112 using std::scanf;
 113 using std::sprintf;
 114 using std::sscanf;
 115 using std::vfprintf;
 116 using std::vprintf;
 117 using std::vsprintf;
 118 using std::fgetc;
 119 using std::fgets;
 120 using std::fputc;
 121 using std::fputs;
 122 using std::getc;
 123 using std::getchar;
 124 using std::gets;
 125 using std::putc;
 126 using std::putchar;
 127 using std::puts;
 128 using std::ungetc;
 129 using std::fread;
 130 using std::fwrite;
 131 using std::fgetpos;
 132 using std::fseek;
 133 using std::fsetpos;
 134 using std::ftell;
 135 using std::rewind;
 136 using std::clearerr;
 137 using std::feof;
 138 using std::ferror;
 139 using std::perror;
 140 #ifndef _LP64
 141 using std::__filbuf;
 142 using 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
 153 extern "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
 160 typedef long            off_t;
 161 #else
 162 typedef __longlong_t    off_t;
 163 #endif
 164 #ifdef  _LARGEFILE64_SOURCE
 165 #ifdef _LP64
 166 typedef off_t           off64_t;
 167 #else
 168 typedef __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
 176 typedef fpos_t          fpos64_t;
 177 #else
 178 typedef __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
 189 typedef __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
 212 extern 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 extern FILE     *fopen64(const char *, const char *);
 219 extern FILE     *freopen64(const char *, const char *, FILE *);
 220 extern FILE     *tmpfile64(void);
 221 extern int      fgetpos64(FILE *, fpos_t *);
 222 extern int      fsetpos64(FILE *, const fpos_t *);
 223 #define fopen                   fopen64
 224 #define freopen                 freopen64
 225 #define tmpfile                 tmpfile64
 226 #define fgetpos                 fgetpos64
 227 #define fsetpos                 fsetpos64
 228 #ifdef  _LARGEFILE_SOURCE
 229 #define fseeko                  fseeko64
 230 #define ftello                  ftello64
 231 #endif
 232 #endif  /* !__PRAGMA_REDEFINE_EXTNAME */
 233 #endif  /* !_LP64 && _FILE_OFFSET_BITS == 64 */
 234 
 235 #ifndef _LP64
 236 extern unsigned char    *_bufendtab[];
 237 extern FILE             *_lastbuf;
 238 #endif
 239 
 240 /* In the LP64 compilation environment, all APIs are already large file */
 241 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
 242 #if !defined(__PRAGMA_REDEFINE_EXTNAME)
 243 #define fopen64         fopen
 244 #define freopen64       freopen
 245 #define tmpfile64       tmpfile
 246 #define fgetpos64       fgetpos
 247 #define fsetpos64       fsetpos
 248 #ifdef  _LARGEFILE_SOURCE
 249 #define fseeko64        fseeko
 250 #define ftello64        ftello
 251 #endif
 252 #endif  /* !__PRAGMA_REDEFINE_EXTNAME */
 253 #endif  /* _LP64 && _LARGEFILE64_SOURCE */
 254 
 255 #ifndef _SSIZE_T
 256 #define _SSIZE_T
 257 #if defined(_LP64) || defined(_I32LPx)
 258 typedef long    ssize_t;        /* size of something in bytes or -1 */
 259 #else
 260 typedef int     ssize_t;        /* (historical version) */
 261 #endif
 262 #endif  /* !_SSIZE_T */
 263 
 264 #if defined(_REENTRANT) || !defined(_STRICT_SYMBOLS)
 265 extern char     *tmpnam_r(char *);
 266 #endif
 267 
 268 #if !defined(_STRICT_SYMBOLS)
 269 extern int fcloseall(void);
 270 extern void setbuffer(FILE *, char *, size_t);
 271 extern int setlinebuf(FILE *);
 272 /* PRINTFLIKE2 */
 273 extern int asprintf(char **, const char *, ...);
 274 /* PRINTFLIKE2 */
 275 extern int vasprintf(char **, const char *, __va_list);
 276 #endif
 277 
 278 #if defined(_XPG7) || !defined(_STRICT_SYMBOLS)
 279 extern ssize_t getdelim(char **_RESTRICT_KYWD, size_t *_RESTRICT_KYWD,
 280         int, FILE *_RESTRICT_KYWD);
 281 extern ssize_t getline(char **_RESTRICT_KYWD, size_t *_RESTRICT_KYWD,
 282         FILE *_RESTRICT_KYWD);
 283 #endif
 284 
 285 /*
 286  * The following are known to POSIX and XOPEN, but not to ANSI-C.
 287  */
 288 #if defined(__XOPEN_OR_POSIX) || !defined(_STRICT_SYMBOLS)
 289 extern FILE     *fdopen(int, const char *);
 290 extern char     *ctermid(char *);
 291 extern int      fileno(FILE *);
 292 #endif
 293 
 294 /*
 295  * The following are known to POSIX.1c, but not to ANSI-C or older XOPEN.
 296  */
 297 #if defined(_REENTRANT) || !defined(_STRICT_SYMBOLS) || \
 298         (_POSIX_C_SOURCE - 0 >= 199506L)
 299 extern void     flockfile(FILE *);
 300 extern int      ftrylockfile(FILE *);
 301 extern void     funlockfile(FILE *);
 302 extern int      getc_unlocked(FILE *);
 303 extern int      getchar_unlocked(void);
 304 extern int      putc_unlocked(int, FILE *);
 305 extern int      putchar_unlocked(int);
 306 #endif
 307 
 308 /*
 309  * The following are known to XOPEN, but not to ANSI-C or POSIX.
 310  */
 311 #if defined(_XOPEN_SOURCE) || !defined(_STRICT_SYMBOLS)
 312 
 313 extern FILE     *popen(const char *, const char *);
 314 extern char     *tempnam(const char *, const char *);
 315 extern int      pclose(FILE *);
 316 
 317 #if !defined(_XOPEN_SOURCE)
 318 /* XOPEN puts this in stdlib.h */
 319 extern int      getsubopt(char **, char *const *, char **);
 320 #endif
 321 
 322 /* Marked LEGACY in SUSv2 and removed in SUSv3 */
 323 #if !defined(_STRICT_XPG6)
 324 extern char     *cuserid(char *);
 325 extern int      getopt(int, char *const *, const char *);
 326 extern char     *optarg;
 327 extern int      optind, opterr, optopt;
 328 extern int      getw(FILE *);
 329 extern int      putw(int, FILE *);
 330 #endif
 331 
 332 #endif  /* defined(_XOPEN_SOURCE) || !defined(_STRICT_SYMBOLS) */
 333 
 334 /*
 335  * The following are defined as part of the Large File Summit interfaces.
 336  */
 337 #if defined(_LARGEFILE_SOURCE) || defined(_XPG5)
 338 extern int      fseeko(FILE *, off_t, int);
 339 extern off_t    ftello(FILE *);
 340 #endif
 341 
 342 /*
 343  * The following are defined as part of the transitional Large File Summit
 344  * interfaces.
 345  */
 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 *);
 355 #endif
 356 
 357 #if !defined(__lint)
 358 
 359 #if defined(_REENTRANT) || !defined(_STRICT_SYMBOLS) || \
 360             (_POSIX_C_SOURCE - 0 >= 199506L)
 361 #ifndef _LP64
 362 #define getc_unlocked(p)        (--(p)->_cnt < 0 \
 363                                         ? __filbuf(p) \
 364                                         : (int)*(p)->_ptr++)
 365 #define putc_unlocked(x, p)     (--(p)->_cnt < 0 \
 366                                         ? __flsbuf((x), (p)) \
 367                                         : (int)(*(p)->_ptr++ = \
 368                                         (unsigned char) (x)))
 369 #endif  /* _LP64 */
 370 #define getchar_unlocked()      getc_unlocked(stdin)
 371 #define putchar_unlocked(x)     putc_unlocked((x), stdout)
 372 #endif  /* defined(_REENTRANT).. */
 373 
 374 #endif  /* !defined(__lint) */
 375 
 376 #ifdef  __cplusplus
 377 }
 378 #endif
 379 
 380 #endif  /* _STDIO_H */