]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/Include/stdio.h
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / Include / stdio.h
diff --git a/StdLib/Include/stdio.h b/StdLib/Include/stdio.h
new file mode 100644 (file)
index 0000000..d6eadf5
--- /dev/null
@@ -0,0 +1,704 @@
+/*-\r
+ * Copyright (c) 1990, 1993\r
+ *  The Regents of the University of California.  All rights reserved.\r
+ *\r
+ * This code is derived from software contributed to Berkeley by\r
+ * Chris Torek.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ * 1. Redistributions of source code must retain the above copyright\r
+ *    notice, this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the\r
+ *    documentation and/or other materials provided with the distribution.\r
+ * 3. Neither the name of the University nor the names of its contributors\r
+ *    may be used to endorse or promote products derived from this software\r
+ *    without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
+ * SUCH DAMAGE.\r
+ *\r
+ *  @(#)stdio.h 8.5 (Berkeley) 4/29/95\r
+ */\r
+/*  $NetBSD: stdio.h,v 1.66.2.3 2007/08/24 20:07:38 liamjfoy Exp $  */\r
+\r
+#ifndef _STDIO_H_\r
+#define _STDIO_H_\r
+\r
+#include  <sys/EfiCdefs.h>\r
+#include  <limits.h>\r
+#include  <sys/ansi.h>\r
+#include  <machine/ansi.h>\r
+\r
+#ifdef _EFI_SIZE_T_\r
+  typedef _EFI_SIZE_T_  size_t;\r
+  #undef _EFI_SIZE_T_\r
+#endif\r
+\r
+/*\r
+ * This is fairly grotesque, but pure ANSI code must not inspect the\r
+ * innards of an fpos_t anyway.  The library internally uses off_t,\r
+ * which we assume is exactly as big as eight chars.\r
+ */\r
+#if (!defined(_ANSI_SOURCE) && !defined(__STRICT_ANSI__)) || defined(_LIBC)\r
+typedef __off_t fpos_t;\r
+#else\r
+typedef struct __sfpos {\r
+  __off_t _pos;\r
+} fpos_t;\r
+#endif\r
+\r
+#define _FSTDIO     /* Define for new stdio with functions. */\r
+\r
+/*\r
+ * NB: to fit things in six character monocase externals, the stdio\r
+ * code uses the prefix `__s' for stdio objects, typically followed\r
+ * by a three-character attempt at a mnemonic.\r
+ */\r
+\r
+/* stdio buffers */\r
+struct __sbuf {\r
+  unsigned char *_base;\r
+  int _size;\r
+};\r
+\r
+/*\r
+ * stdio state variables.\r
+ *\r
+ * The following always hold:\r
+ *\r
+ *  if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),\r
+ *    _lbfsize is -_bf._size, else _lbfsize is 0\r
+ *  if _flags&__SRD, _w is 0\r
+ *  if _flags&__SWR, _r is 0\r
+ *\r
+ * This ensures that the getc and putc macros (or inline functions) never\r
+ * try to write or read from a file that is in `read' or `write' mode.\r
+ * (Moreover, they can, and do, automatically switch from read mode to\r
+ * write mode, and back, on "r+" and "w+" files.)\r
+ *\r
+ * _lbfsize is used only to make the inline line-buffered output stream\r
+ * code as compact as possible.\r
+ *\r
+ * _ub, _up, and _ur are used when ungetc() pushes back more characters\r
+ * than fit in the current _bf, or when ungetc() pushes back a character\r
+ * that does not match the previous one in _bf.  When this happens,\r
+ * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff\r
+ * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.\r
+ *\r
+ * NB: see WARNING above before changing the layout of this structure!\r
+ */\r
+typedef struct __sFILE {\r
+  unsigned char  *_p;         /* current position in (some) buffer */\r
+  int             _r;         /* read space left for getc() */\r
+  int             _w;         /* write space left for putc() */\r
+  unsigned short  _flags;     /* flags, below; this FILE is free if 0 */\r
+  short           _file;      /* fileno, if Unix descriptor, else -1 */\r
+  struct  __sbuf  _bf;        /* the buffer (at least 1 byte, if !NULL) */\r
+  int             _lbfsize;   /* 0 or -_bf._size, for inline putc */\r
+\r
+  /* operations */\r
+  void           *_cookie;    /* cookie passed to io functions */\r
+  int           (*_close)(void *);\r
+  int           (*_read) (void *, char *, int);\r
+  fpos_t        (*_seek) (void *, fpos_t, int);\r
+  int           (*_write)(void *, const char *, int);\r
+\r
+  /* file extension */\r
+  struct  __sbuf  _ext;\r
+\r
+  /* separate buffer for long sequences of ungetc() */\r
+  unsigned char  *_up;        /* saved _p when _p is doing ungetc data */\r
+  int             _ur;        /* saved _r when _r is counting ungetc data */\r
+\r
+  /* tricks to meet minimum requirements even when malloc() fails */\r
+  unsigned char   _ubuf[3];   /* guarantee an ungetc() buffer */\r
+  unsigned char   _nbuf[1];   /* guarantee a getc() buffer */\r
+\r
+  /* separate buffer for fgetln() when line crosses buffer boundary */\r
+  struct  __sbuf  _lb;        /* buffer for fgetln() */\r
+\r
+  /* Unix stdio files get aligned to block boundaries on fseek() */\r
+  int             _blksize;   /* stat.st_blksize (may be != _bf._size) */\r
+  fpos_t          _offset;    /* current lseek offset */\r
+} FILE;\r
+\r
+__BEGIN_DECLS\r
+extern FILE   __sF[];\r
+__END_DECLS\r
+\r
+#define __SLBF  0x0001    /* line buffered */\r
+#define __SNBF  0x0002    /* unbuffered */\r
+#define __SRD   0x0004    /* OK to read */\r
+#define __SWR   0x0008    /* OK to write */\r
+  /* RD and WR are never simultaneously asserted */\r
+#define __SRW   0x0010    /* open for reading & writing */\r
+#define __SEOF  0x0020    /* found EOF */\r
+#define __SERR  0x0040    /* found error */\r
+#define __SMBF  0x0080    /* _buf is from malloc */\r
+#define __SAPP  0x0100    /* fdopen()ed in append mode */\r
+#define __SSTR  0x0200    /* this is an sprintf/snprintf string */\r
+#define __SOPT  0x0400    /* do fseek() optimization */\r
+#define __SNPT  0x0800    /* do not do fseek() optimization */\r
+#define __SOFF  0x1000    /* set iff _offset is in fact correct */\r
+#define __SMOD  0x2000    /* true => fgetln modified _p text */\r
+#define __SALC  0x4000    /* allocate string space dynamically */\r
+\r
+/*\r
+ * The following three definitions are for ANSI C, which took them\r
+ * from System V, which brilliantly took internal interface macros and\r
+ * made them official arguments to setvbuf(), without renaming them.\r
+ * Hence, these ugly _IOxxx names are *supposed* to appear in user code.\r
+ *\r
+ * Although numbered as their counterparts above, the implementation\r
+ * does not rely on this.\r
+ */\r
+#define _IOFBF  0   /* setvbuf should set fully buffered */\r
+#define _IOLBF  1   /* setvbuf should set line buffered */\r
+#define _IONBF  2   /* setvbuf should set unbuffered */\r
+\r
+#define BUFSIZ  1024    /* size of buffer used by setbuf */\r
+#define EOF     (-1)\r
+\r
+/*\r
+ * FOPEN_MAX is a minimum maximum, and is the number of streams that\r
+ * stdio can provide without attempting to allocate further resources\r
+ * (which could fail).  Do not use this for anything.\r
+ */\r
+#define FOPEN_MAX     OPEN_MAX    /* must be <= OPEN_MAX <sys/syslimits.h> */\r
+#define FILENAME_MAX  PATH_MAX    /* must be <= PATH_MAX <sys/syslimits.h> */\r
+\r
+#define L_tmpnam      PATH_MAX    /* must be == PATH_MAX */\r
+\r
+#ifndef TMP_MAX\r
+#define TMP_MAX     308915776 /* Legacy */\r
+#endif\r
+\r
+/* Always ensure that these are consistent with <fcntl.h>! */\r
+#ifndef SEEK_SET\r
+#define SEEK_SET  0 /* set file offset to offset */\r
+#endif\r
+#ifndef SEEK_CUR\r
+#define SEEK_CUR  1 /* set file offset to current plus offset */\r
+#endif\r
+#ifndef SEEK_END\r
+#define SEEK_END  2 /* set file offset to EOF plus offset */\r
+#endif\r
+\r
+#define stdin   (&__sF[0])\r
+#define stdout  (&__sF[1])\r
+#define stderr  (&__sF[2])\r
+\r
+/*\r
+ * Functions defined in ANSI C standard.\r
+ */\r
+__BEGIN_DECLS\r
+void      clearerr(FILE *);\r
+int       fclose  (FILE *);\r
+int       feof    (FILE *);\r
+int       ferror  (FILE *);\r
+int       fflush  (FILE *);\r
+int       fgetc   (FILE *);\r
+int       fgetpos (FILE * __restrict, fpos_t * __restrict);\r
+char     *fgets   (char * __restrict, int, FILE * __restrict);\r
+FILE     *fopen   (const char * __restrict , const char * __restrict);\r
+\r
+/** The fprintf function writes output to the stream pointed to by stream,\r
+    under control of the string pointed to by format that specifies how\r
+    subsequent arguments are converted for output. If there are insufficient\r
+    arguments for the format, the behavior is undefined. If the format is\r
+    exhausted while arguments remain, the excess arguments are evaluated\r
+    (as always) but are otherwise ignored. The fprintf function returns when\r
+    the end of the format string is encountered.\r
+\r
+    The format shall be a multibyte character sequence, beginning and ending in\r
+    its initial shift state. The format is composed of zero or more directives:\r
+    ordinary multibyte characters (not %), which are copied unchanged to the\r
+    output stream; and conversion specifications, each of which results in\r
+    fetching zero or more subsequent arguments, converting them, if applicable,\r
+    according to the corresponding conversion specifier, and then writing the\r
+    result to the output stream.\r
+\r
+    Each conversion specification is introduced by the character %. After\r
+    the %, the following appear in sequence:\r
+      - Zero or more flags (in any order) that modify the meaning of the\r
+        conversion specification.\r
+      - An optional minimum field width. If the converted value has fewer\r
+        characters than the field width, it is padded with spaces (by default)\r
+        on the left (or right, if the left adjustment flag, described later,\r
+        has been given) to the field width. The field width takes the form of\r
+        an asterisk * (described later) or a nonnegative decimal integer.\r
+      - An optional precision that gives the minimum number of digits to appear\r
+        for the d, i, o, u, x, and X conversions, the number of digits to\r
+        appear after the decimal-point character for e, E, f, and F\r
+        conversions, the maximum number of significant digits for the g and G\r
+        conversions, or the maximum number of bytes to be written for s\r
+        conversions. The precision takes the form of a period (.) followed\r
+        either by an asterisk * (described later) or by an optional decimal\r
+        integer; if only the period is specified, the precision is taken as\r
+        zero. If a precision appears with any other conversion specifier, the\r
+        behavior is undefined.\r
+      - An optional length modifier that specifies the size of the argument.\r
+      - A conversion specifier character that specifies the type of conversion\r
+        to be applied.\r
+\r
+    As noted above, a field width, or precision, or both, may be indicated by\r
+    an asterisk. In this case, an int argument supplies the field width or\r
+    precision. The arguments specifying field width, or precision, or both, shall\r
+    appear (in that order) before the argument (if any) to be converted. A negative\r
+    field width argument is taken as a - flag followed by a positive field width.\r
+    A negative precision argument is taken as if the precision were omitted.\r
+\r
+    The flag characters and their meanings are:\r
+      -     The result of the conversion is left-justified within the field.\r
+            (It is right-justified if this flag is not specified.)\r
+      +     The result of a signed conversion always begins with a plus or\r
+            minus sign. (It begins with a sign only when a negative value is\r
+            converted if this flag is not specified.)\r
+      space If the first character of a signed conversion is not a sign, or\r
+            if a signed conversion results in no characters, a space is\r
+            prefixed to the result. If the space and + flags both appear, the\r
+            space flag is ignored.\r
+      #     The result is converted to an "alternative form". For o\r
+            conversion, it increases the precision, if and only if necessary,\r
+            to force the first digit of the result to be a zero (if the value\r
+            and precision are both 0, a single 0 is printed). For x (or X)\r
+            conversion, a nonzero result has 0x (or 0X) prefixed to it. For e,\r
+            E, f, F, g, and G conversions, the result of converting a\r
+            floating-point number always contains a decimal-point character,\r
+            even if no digits follow it. (Normally, a decimal-point character\r
+            appears in the result of these conversions only if a digit follows\r
+            it.) For g and G conversions, trailing zeros are not removed from\r
+            the result. For other conversions, the behavior is undefined.\r
+      0     For d, i, o, u, x, X, e, E, f, F, g, and G conversions, leading\r
+            zeros (following any indication of sign or base) are used to pad to\r
+            the field width rather than performing space padding, except when\r
+            converting an infinity or NaN. If the 0 and - flags both appear,\r
+            the 0 flag is ignored. For d, i, o, u, x, and X conversions, if a\r
+            precision is specified, the 0 flag is ignored. For other\r
+            conversions, the behavior is undefined.\r
+\r
+    The length modifiers and their meanings are:\r
+      hh    Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a signed char or unsigned char argument (the argument\r
+            will have been promoted according to the integer promotions, but\r
+            its value shall be converted to signed char or unsigned char before\r
+            printing); or that a following n conversion specifier applies to a\r
+            pointer to a signed char argument.\r
+      h     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a short int or unsigned short int argument (the argument\r
+            will have been promoted according to the integer promotions, but\r
+            its value shall be converted to short int or unsigned short int\r
+            before printing); or that a following n conversion specifier\r
+            applies to a pointer to a short int argument.\r
+      l (ell)   Specifies that a following d, i, o, u, x, or X conversion\r
+            specifier applies to a long int or unsigned long int argument; that\r
+            a following n conversion specifier applies to a pointer to a long\r
+            int argument; that a following c conversion specifier applies to a\r
+            wint_t argument; that a following s conversion specifier applies to\r
+            a pointer to a wchar_t argument; or has no effect on a following e,\r
+            E, f, F, g, or G conversion specifier.\r
+      ll (ell-ell)  Specifies that a following d, i, o, u, x, or X conversion\r
+            specifier applies to a long long int or unsigned long long int\r
+            argument; or that a following n conversion specifier applies to a\r
+            pointer to a long long int argument.\r
+      j     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to an intmax_t or uintmax_t argument; or that a following n\r
+            conversion specifier applies to a pointer to an intmax_t argument.\r
+      z     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a size_t or the corresponding signed integer type\r
+            argument; or that a following n conversion specifier applies to a\r
+            pointer to a signed integer type corresponding to size_t argument.\r
+      t     Specifies that a following d, i, o, u, x, or X conversion specifier\r
+            applies to a ptrdiff_t or the corresponding unsigned integer type\r
+            argument; or that a following n conversion specifier applies to a\r
+            pointer to a ptrdiff_t argument.\r
+      L     Specifies that a following e, E, f, F, g, or G conversion specifier\r
+            applies to a long double argument.\r
+\r
+    If a length modifier appears with any conversion specifier other than as\r
+    specified above, the behavior is undefined.\r
+\r
+    The conversion specifiers and their meanings are:\r
+      d,i       The int argument is converted to signed decimal in the style\r
+            [-]dddd. The precision specifies the minimum number of digits to\r
+            appear; if the value being converted can be represented in fewer\r
+            digits, it is expanded with leading zeros. The default precision\r
+            is 1. The result of converting a zero value with a precision of\r
+            zero is no characters.\r
+      o,u,x,X   The unsigned int argument is converted to unsigned octal (o),\r
+            unsigned decimal (u), or unsigned hexadecimal notation (x or X) in\r
+            the style dddd; the letters abcdef are used for x conversion and\r
+            the letters ABCDEF for X conversion. The precision specifies the\r
+            minimum number of digits to appear; if the value being converted\r
+            can be represented in fewer digits, it is expanded with leading\r
+            zeros. The default precision is 1. The result of converting a zero\r
+            value with a precision of zero is no characters.\r
+      f,F       A double argument representing a floating-point number is\r
+            converted to decimal notation in the style [-]ddd.ddd, where the\r
+            number of digits after the decimal-point character is equal to the\r
+            precision specification. If the precision is missing, it is taken\r
+            as 6; if the precision is zero and the # flag is not specified, no\r
+            decimal-point character appears. If a decimal-point character\r
+            appears, at least one digit appears before it. The value is rounded\r
+            to the appropriate number of digits.\r
+                A double argument representing an infinity is converted in one\r
+            of the styles [-]inf or [-]infinity - which style is\r
+            implementation-defined. A double argument representing a NaN is\r
+            converted in one of the styles [-]nan or [-]nan(n-char-sequence)\r
+            - which style, and the meaning of any n-char-sequence, is\r
+            implementation-defined. The F conversion specifier produces INF,\r
+            INFINITY, or NAN instead of inf, infinity, or nan, respectively.\r
+      e,E       A double argument representing a floating-point number is\r
+            converted in the style [-]d.ddd e[+-]dd, where there is one digit\r
+            (which is nonzero if the argument is nonzero) before the\r
+            decimal-point character and the number of digits after it is equal\r
+            to the precision; if the precision is missing, it is taken as 6; if\r
+            the precision is zero and the # flag is not specified, no\r
+            decimal-point character appears. The value is rounded to the\r
+            appropriate number of digits. The E conversion specifier produces a\r
+            number with E instead of e introducing the exponent. The exponent\r
+            always contains at least two digits, and only as many more digits\r
+            as necessary to represent the exponent. If the value is zero, the\r
+            exponent is zero.\r
+                A double argument representing an infinity or NaN is converted\r
+            in the style of an f or F conversion specifier.\r
+      g,G       A double argument representing a floating-point number is\r
+            converted in style f or e (or in style F or E in the case of a G\r
+            conversion specifier), depending on the value converted and the\r
+            precision. Let P equal the precision if nonzero, 6 if the precision\r
+            is omitted, or 1 if the precision is zero. Then, if a conversion\r
+            with style E would have an exponent of X:\r
+              - if P > X = -4, the conversion is with style f (or F) and\r
+                precision P - (X + 1).\r
+              - otherwise, the conversion is with style e (or E) and\r
+                precision P - 1.\r
+\r
+            Finally, unless the # flag is used, any trailing zeros are removed\r
+            from the fractional portion of the result and the decimal-point\r
+            character is removed if there is no fractional portion remaining.\r
+            A double argument representing an infinity or NaN is converted in\r
+            the style of an f or F conversion specifier.\r
+      c         If no l length modifier is present, the int argument is\r
+            converted to an unsigned char, and the resulting character is\r
+            written. If an l length modifier is present, the wint_t argument is\r
+            converted as if by an ls conversion specification with no precision\r
+            and an argument that points to the initial element of a two-element\r
+            array of wchar_t, the first element containing the wint_t argument\r
+            to the lc conversion specification and the second a null wide\r
+            character.\r
+      s         If no l length modifier is present, the argument is a pointer\r
+            to the initial element of an array of character type. Characters\r
+            from the array are written up to (but not including) the\r
+            terminating null character. If the precision is specified, no more\r
+            than that many bytes are written. If the precision is not specified\r
+            or is greater than the size of the array, the array shall contain a\r
+            null character.\r
+                If an l length modifier is present, the argument shall be a\r
+            pointer to the initial element of an array of wchar_t type. Wide\r
+            characters from the array are converted to multibyte characters\r
+            (each as if by a call to the wcrtomb function, with the conversion\r
+            state described by an mbstate_t object initialized to zero before\r
+            the first wide character is converted) up to and including a\r
+            terminating null wide character. The resulting multibyte characters\r
+            are written up to (but not including) the terminating null\r
+            character (byte). If no precision is specified, the array shall\r
+            contain a null wide character. If a precision is specified, no more\r
+            than that many bytes are written (including shift sequences, if\r
+            any), and the array shall contain a null wide character if, to\r
+            equal the multibyte character sequence length given by the\r
+            precision, the function would need to access a wide character one\r
+            past the end of the array. In no case is a partial multibyte\r
+            character written.\r
+      p         The argument shall be a pointer to void. The value of the\r
+            pointer is converted to a sequence of printing characters, in an\r
+            implementation-defined manner.\r
+      n         The argument shall be a pointer to signed integer into which is\r
+            written the number of characters written to the output stream so\r
+            far by this call to fprintf. No argument is converted, but one is\r
+            consumed. If the conversion specification includes any flags, a\r
+            field width, or a precision, the behavior is undefined.\r
+      %         A % character is written. No argument is converted. The\r
+            complete conversion specification shall be %%.\r
+\r
+    In no case does a nonexistent or small field width cause truncation of a\r
+    field; if the result of a conversion is wider than the field width, the\r
+    field is expanded to contain the conversion result.\r
+\r
+    @param[in]  stream    An open File specifier to which the output is sent.\r
+    @param[in]  format    A multi-byte character sequence containing characters\r
+                          to be copied unchanged, and conversion specifiers\r
+                          which convert their associated arguments.  Copied and\r
+                          converted characters are sent to the output stream.\r
+    @param      ...       Variable number of parameters as required by format.\r
+\r
+    @return     The fprintf function returns the number of characters\r
+                transmitted, or a negative value if an output or encoding\r
+                error occurred.\r
+\r
+**/\r
+int       fprintf (FILE * __restrict stream, const char * __restrict format, ...);\r
+\r
+int       fputc   (int, FILE *);\r
+int       fputs   (const char * __restrict, FILE * __restrict);\r
+size_t    fread   (void * __restrict, size_t, size_t, FILE * __restrict);\r
+FILE     *freopen (const char * __restrict, const char * __restrict, FILE * __restrict);\r
+int       fscanf  (FILE * __restrict, const char * __restrict, ...);\r
+int       fseek   (FILE *, long, int);\r
+int       fsetpos (FILE *, const fpos_t *);\r
+long      ftell   (FILE *);\r
+size_t    fwrite  (const void * __restrict, size_t, size_t, FILE * __restrict);\r
+int       getc    (FILE *);\r
+int       getchar (void);\r
+void      perror  (const char *);\r
+int       printf  (const char * __restrict, ...);\r
+int       putc    (int, FILE *);\r
+int       putchar (int);\r
+int       puts    (const char *);\r
+int       remove  (const char *);\r
+void      rewind  (FILE *);\r
+int       scanf   (const char * __restrict, ...);\r
+void      setbuf  (FILE * __restrict, char * __restrict);\r
+int       setvbuf (FILE * __restrict, char * __restrict, int, size_t);\r
+int       sscanf  (const char * __restrict, const char * __restrict, ...);\r
+FILE     *tmpfile (void);\r
+int       ungetc  (int, FILE *);\r
+int       vfprintf(FILE * __restrict, const char * __restrict, _BSD_VA_LIST_);\r
+int       vprintf (const char * __restrict, _BSD_VA_LIST_);\r
+\r
+#ifndef __AUDIT__\r
+char     *gets    (char *);\r
+int       sprintf (char * __restrict, const char * __restrict, ...);\r
+char     *tmpnam  (char *);\r
+int       vsprintf(char * __restrict, const char * __restrict, _BSD_VA_LIST_);\r
+#endif\r
+\r
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)\r
+int       rename  (const char *, const char *) __RENAME(__posix_rename);\r
+#else\r
+int       rename  (const char *, const char *);\r
+#endif\r
+__END_DECLS\r
+\r
+/*\r
+ * IEEE Std 1003.1-90\r
+ */\r
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \\r
+    defined(_NETBSD_SOURCE)\r
+  #define L_ctermid 1024  /* size for ctermid(); PATH_MAX */\r
+  #define L_cuserid 9     /* size for cuserid(); UT_NAMESIZE + 1 */\r
+\r
+  __BEGIN_DECLS\r
+  char  *ctermid(char *);\r
+  #ifndef __CUSERID_DECLARED\r
+    #define __CUSERID_DECLARED\r
+    /* also declared in unistd.h */\r
+    char  *cuserid(char *);\r
+  #endif /* __CUSERID_DECLARED */\r
+  FILE  *fdopen(int, const char *);\r
+  int  fileno(FILE *);\r
+  __END_DECLS\r
+#endif /* not ANSI */\r
+\r
+/*\r
+ * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2\r
+ */\r
+#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \\r
+    defined(_REENTRANT) || defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  void    flockfile       (FILE *);\r
+  int     ftrylockfile    (FILE *);\r
+  void    funlockfile     (FILE *);\r
+  int     getc_unlocked   (FILE *);\r
+  int     getchar_unlocked(void);\r
+  int     putc_unlocked   (int, FILE *);\r
+  int     putchar_unlocked(int);\r
+  __END_DECLS\r
+#endif /* _POSIX_C_SOURCE >= 1995056 || _XOPEN_SOURCE >= 500 || ... */\r
+\r
+/*\r
+ * Functions defined in POSIX 1003.2 and XPG2 or later.\r
+ */\r
+#if (_POSIX_C_SOURCE - 0) >= 2 || (_XOPEN_SOURCE - 0) >= 2 || \\r
+    defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  int     pclose  (FILE *);\r
+  FILE   *popen   (const char *, const char *);\r
+  __END_DECLS\r
+#endif\r
+\r
+/*\r
+ * Functions defined in ISO XPG4.2, ISO C99, POSIX 1003.1-2001 or later.\r
+ */\r
+#if ((__STDC_VERSION__ - 0) >= 199901L) || \\r
+    ((_POSIX_C_SOURCE - 0) >= 200112L) || \\r
+    (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \\r
+    ((_XOPEN_SOURCE - 0) >= 500) || \\r
+    defined(_ISOC99_SOURCE) || defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  int     snprintf (char * __restrict, size_t, const char * __restrict, ...)\r
+          __attribute__((__format__(__printf__, 3, 4)));\r
+  int     vsnprintf(char * __restrict, size_t, const char * __restrict, _BSD_VA_LIST_)\r
+          __attribute__((__format__(__printf__, 3, 0)));\r
+  __END_DECLS\r
+#endif\r
+\r
+/*\r
+ * Functions defined in XPG4.2.\r
+ */\r
+#if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)\r
+  __BEGIN_DECLS\r
+  int   getw(FILE *);\r
+  int   putw(int, FILE *);\r
+  char *mkdtemp(char *);\r
+  int   mkstemp(char *);\r
+  char *mktemp(char *);\r
+\r
+  #ifndef __AUDIT__\r
+    char *tempnam(const char *, const char *);\r
+  #endif\r
+  __END_DECLS\r
+#endif\r
+\r
+/*\r
+ * X/Open CAE Specification Issue 5 Version 2\r
+ */\r
+#ifndef off_t\r
+  typedef __off_t   off_t;\r
+  #define off_t   __off_t\r
+#endif /* off_t */\r
+\r
+__BEGIN_DECLS\r
+int  fseeko(FILE *, off_t, int);\r
+off_t  ftello(FILE *);\r
+__END_DECLS\r
+\r
+/*\r
+ * Routines that are purely local.\r
+ */\r
+#if defined(_NETBSD_SOURCE)\r
+\r
+  #define FPARSELN_UNESCESC 0x01\r
+  #define FPARSELN_UNESCCONT  0x02\r
+  #define FPARSELN_UNESCCOMM  0x04\r
+  #define FPARSELN_UNESCREST  0x08\r
+  #define FPARSELN_UNESCALL 0x0f\r
+\r
+  __BEGIN_DECLS\r
+  //int     asprintf(char ** __restrict, const char * __restrict, ...)\r
+  //      __attribute__((__format__(__printf__, 2, 3)));\r
+  char   *fgetln(FILE * __restrict, size_t * __restrict);\r
+  char   *fparseln(FILE *, size_t *, size_t *, const char[3], int);\r
+  int     fpurge(FILE *);\r
+  void    setbuffer(FILE *, char *, int);\r
+  int     setlinebuf(FILE *);\r
+  int     vasprintf(char ** __restrict, const char * __restrict,\r
+        _BSD_VA_LIST_)\r
+        __attribute__((__format__(__printf__, 2, 0)));\r
+  int     vscanf(const char * __restrict, _BSD_VA_LIST_)\r
+        __attribute__((__format__(__scanf__, 1, 0)));\r
+  int     vfscanf(FILE * __restrict, const char * __restrict,\r
+        _BSD_VA_LIST_)\r
+        __attribute__((__format__(__scanf__, 2, 0)));\r
+  int     vsscanf(const char * __restrict, const char * __restrict,\r
+        _BSD_VA_LIST_)\r
+        __attribute__((__format__(__scanf__, 2, 0)));\r
+  const char *fmtcheck(const char *, const char *)\r
+        __attribute__((__format_arg__(2)));\r
+  __END_DECLS\r
+\r
+  /*\r
+   * Stdio function-access interface.\r
+   */\r
+  __BEGIN_DECLS\r
+  FILE  *funopen(const void *,\r
+      int (*)(void *, char *, int),\r
+      int (*)(void *, const char *, int),\r
+      fpos_t (*)(void *, fpos_t, int),\r
+      int (*)(void *));\r
+  __END_DECLS\r
+  //#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)\r
+  //#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)\r
+#endif /* _NETBSD_SOURCE */\r
+\r
+/*\r
+ * Functions internal to the implementation.\r
+ */\r
+__BEGIN_DECLS\r
+int __srget(FILE *);\r
+int __swbuf(int, FILE *);\r
+__END_DECLS\r
+\r
+/*\r
+ * The __sfoo macros are here so that we can\r
+ * define function versions in the C library.\r
+ */\r
+#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))\r
+#if defined(__GNUC__) && defined(__STDC__)\r
+  static __inline int __sputc(int _c, FILE *_p) {\r
+    if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))\r
+      return (*_p->_p++ = _c);\r
+    else\r
+      return (__swbuf(_c, _p));\r
+  }\r
+#else\r
+  /*\r
+   * This has been tuned to generate reasonable code on the vax using pcc.\r
+   */\r
+  #define __sputc(c, p) \\r
+    (--(p)->_w < 0 ? \\r
+      (p)->_w >= (p)->_lbfsize ? \\r
+        (*(p)->_p = (unsigned char)(c)), *(p)->_p != '\n' ? \\r
+          (int)*(p)->_p++ : \\r
+          __swbuf('\n', p) : \\r
+        __swbuf((int)(c), p) : \\r
+      (*(p)->_p = (unsigned char)(c), (int)*(p)->_p++))\r
+#endif\r
+\r
+#define __sfeof(p)      (((p)->_flags & __SEOF) != 0)\r
+#define __sferror(p)    (((p)->_flags & __SERR) != 0)\r
+#define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))\r
+#define __sfileno(p)    ((p)->_file)\r
+\r
+#ifndef __lint__\r
+  #if !defined(_REENTRANT) && !defined(_PTHREADS)\r
+    #define feof(p)     __sfeof(p)\r
+    #define ferror(p)   __sferror(p)\r
+    #define clearerr(p) __sclearerr(p)\r
+\r
+    #define getc(fp)    __sgetc(fp)\r
+    #define putc(x, fp) __sputc(x, fp)\r
+  #endif /* !_REENTRANT && !_PTHREADS */\r
+#endif /* __lint__ */\r
+\r
+#define getchar()   getc(stdin)\r
+#define putchar(x)  putc(x, stdout)\r
+\r
+#if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \\r
+    defined(_NETBSD_SOURCE)\r
+  #if !defined(_REENTRANT) && !defined(_PTHREADS)\r
+    #define fileno(p) __sfileno(p)\r
+  #endif /* !_REENTRANT && !_PTHREADS */\r
+#endif /* !_ANSI_SOURCE */\r
+\r
+#if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \\r
+    defined(_REENTRANT) || defined(_NETBSD_SOURCE)\r
+  #define getc_unlocked(fp) __sgetc(fp)\r
+  #define putc_unlocked(x, fp)  __sputc(x, fp)\r
+\r
+  #define getchar_unlocked()  getc_unlocked(stdin)\r
+  #define putchar_unlocked(x) putc_unlocked(x, stdout)\r
+#endif /* _POSIX_C_SOURCE >= 199506 || _XOPEN_SOURCE >= 500 || _REENTRANT... */\r
+\r
+#endif /* _STDIO_H_ */\r