Home | History | Annotate | Download | only in include
      1 // -*- C++ -*-
      2 //===---------------------------- cstdio ----------------------------------===//
      3 //
      4 //                     The LLVM Compiler Infrastructure
      5 //
      6 // This file is dual licensed under the MIT and the University of Illinois Open
      7 // Source Licenses. See LICENSE.TXT for details.
      8 //
      9 //===----------------------------------------------------------------------===//
     10 
     11 #ifndef _LIBCPP_CSTDIO
     12 #define _LIBCPP_CSTDIO
     13 
     14 /*
     15     cstdio synopsis
     16 
     17 Macros:
     18 
     19     BUFSIZ
     20     EOF
     21     FILENAME_MAX
     22     FOPEN_MAX
     23     L_tmpnam
     24     NULL
     25     SEEK_CUR
     26     SEEK_END
     27     SEEK_SET
     28     TMP_MAX
     29     _IOFBF
     30     _IOLBF
     31     _IONBF
     32     stderr
     33     stdin
     34     stdout
     35 
     36 namespace std
     37 {
     38 
     39 Types:
     40 
     41 FILE
     42 fpos_t
     43 size_t
     44 
     45 int remove(const char* filename);
     46 int rename(const char* old, const char* new);
     47 FILE* tmpfile(void);
     48 char* tmpnam(char* s);
     49 int fclose(FILE* stream);
     50 int fflush(FILE* stream);
     51 FILE* fopen(const char* restrict filename, const char* restrict mode);
     52 FILE* freopen(const char* restrict filename, const char * restrict mode,
     53               FILE * restrict stream);
     54 void setbuf(FILE* restrict stream, char* restrict buf);
     55 int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size);
     56 int fprintf(FILE* restrict stream, const char* restrict format, ...);
     57 int fscanf(FILE* restrict stream, const char * restrict format, ...);
     58 int printf(const char* restrict format, ...);
     59 int scanf(const char* restrict format, ...);
     60 int snprintf(char* restrict s, size_t n, const char* restrict format, ...);    // C99
     61 int sprintf(char* restrict s, const char* restrict format, ...);
     62 int sscanf(const char* restrict s, const char* restrict format, ...);
     63 int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg);
     64 int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg);  // C99
     65 int vprintf(const char* restrict format, va_list arg);
     66 int vscanf(const char* restrict format, va_list arg);                          // C99
     67 int vsnprintf(char* restrict s, size_t n, const char* restrict format,         // C99
     68               va_list arg);
     69 int vsprintf(char* restrict s, const char* restrict format, va_list arg);
     70 int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99
     71 int fgetc(FILE* stream);
     72 char* fgets(char* restrict s, int n, FILE* restrict stream);
     73 int fputc(int c, FILE* stream);
     74 int fputs(const char* restrict s, FILE* restrict stream);
     75 int getc(FILE* stream);
     76 int getchar(void);
     77 char* gets(char* s);  // removed in C++14
     78 int putc(int c, FILE* stream);
     79 int putchar(int c);
     80 int puts(const char* s);
     81 int ungetc(int c, FILE* stream);
     82 size_t fread(void* restrict ptr, size_t size, size_t nmemb,
     83              FILE* restrict stream);
     84 size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb,
     85               FILE* restrict stream);
     86 int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
     87 int fseek(FILE* stream, long offset, int whence);
     88 int fsetpos(FILE*stream, const fpos_t* pos);
     89 long ftell(FILE* stream);
     90 void rewind(FILE* stream);
     91 void clearerr(FILE* stream);
     92 int feof(FILE* stream);
     93 int ferror(FILE* stream);
     94 void perror(const char* s);
     95 
     96 }  // std
     97 */
     98 
     99 #include <__config>
    100 #include <stdio.h>
    101 
    102 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
    103 #pragma GCC system_header
    104 #endif
    105 
    106 // snprintf
    107 #if defined(_LIBCPP_MSVCRT)
    108 #include "support/win32/support.h"
    109 #endif
    110 
    111 #ifdef getc
    112 inline _LIBCPP_INLINE_VISIBILITY int __libcpp_getc(FILE* __stream) {return getc(__stream);}
    113 #undef getc
    114 inline _LIBCPP_INLINE_VISIBILITY int getc(FILE* __stream) {return __libcpp_getc(__stream);}
    115 #endif  // getc
    116 
    117 #ifdef getchar
    118 inline _LIBCPP_INLINE_VISIBILITY int __libcpp_getchar(void) {return getchar();}
    119 #undef getchar
    120 inline _LIBCPP_INLINE_VISIBILITY int getchar(void) {return __libcpp_getchar();}
    121 #endif  // getchar
    122 
    123 #ifdef putc
    124 inline _LIBCPP_INLINE_VISIBILITY int __libcpp_putc(int __c, FILE* __stream) {return putc(__c, __stream);}
    125 #undef putc
    126 inline _LIBCPP_INLINE_VISIBILITY int putc(int __c, FILE* __stream) {return __libcpp_putc(__c, __stream);}
    127 #endif  // putc
    128 
    129 #ifdef __ANDROID__
    130 // In bionic's stdio.h, putchar appears as both a function prototype and a macro (later
    131 // in the same header).  Because it's defined as a macro, the following code snippet replaces
    132 // it with a function but with *different* visibility.  GCC 4.x complains [-Wattributes]
    133 //
    134 //   include/stdio.h:236:5: warning: conflicts with previous declaration here [-Wattributes]
    135 //     int  putchar(int);
    136 //
    137 // Undefine putchar to avoid redefinition, and putchar does exist in libc.so
    138 //
    139 #undef putchar
    140 #endif
    141 
    142 #ifdef putchar
    143 inline _LIBCPP_INLINE_VISIBILITY int __libcpp_putchar(int __c) {return putchar(__c);}
    144 #undef putchar
    145 inline _LIBCPP_INLINE_VISIBILITY int putchar(int __c) {return __libcpp_putchar(__c);}
    146 #endif  // putchar
    147 
    148 #ifdef clearerr
    149 inline _LIBCPP_INLINE_VISIBILITY void __libcpp_clearerr(FILE* __stream) {return clearerr(__stream);}
    150 #undef clearerr
    151 inline _LIBCPP_INLINE_VISIBILITY void clearerr(FILE* __stream) {return __libcpp_clearerr(__stream);}
    152 #endif  // clearerr
    153 
    154 #ifdef feof
    155 inline _LIBCPP_INLINE_VISIBILITY int __libcpp_feof(FILE* __stream) {return feof(__stream);}
    156 #undef feof
    157 inline _LIBCPP_INLINE_VISIBILITY int feof(FILE* __stream) {return __libcpp_feof(__stream);}
    158 #endif  // feof
    159 
    160 #ifdef ferror
    161 inline _LIBCPP_INLINE_VISIBILITY int __libcpp_ferror(FILE* __stream) {return ferror(__stream);}
    162 #undef ferror
    163 inline _LIBCPP_INLINE_VISIBILITY int ferror(FILE* __stream) {return __libcpp_ferror(__stream);}
    164 #endif  // ferror
    165 
    166 _LIBCPP_BEGIN_NAMESPACE_STD
    167 
    168 using ::FILE;
    169 using ::fpos_t;
    170 using ::size_t;
    171 
    172 using ::remove;
    173 using ::rename;
    174 using ::tmpfile;
    175 using ::tmpnam;
    176 using ::fclose;
    177 using ::fflush;
    178 using ::fopen;
    179 using ::freopen;
    180 using ::setbuf;
    181 using ::setvbuf;
    182 using ::fprintf;
    183 using ::fscanf;
    184 using ::printf;
    185 using ::scanf;
    186 using ::snprintf;
    187 using ::sprintf;
    188 using ::sscanf;
    189 #ifndef _LIBCPP_MSVCRT
    190 using ::vfprintf;
    191 using ::vfscanf;
    192 using ::vscanf;
    193 using ::vsscanf;
    194 #endif // _LIBCPP_MSVCRT
    195 using ::vprintf;
    196 using ::vsnprintf;
    197 using ::vsprintf;
    198 using ::fgetc;
    199 using ::fgets;
    200 using ::fputc;
    201 using ::fputs;
    202 using ::getc;
    203 using ::getchar;
    204 #if _LIBCPP_STD_VER <= 11
    205 using ::gets;
    206 #endif
    207 using ::putc;
    208 using ::putchar;
    209 using ::puts;
    210 using ::ungetc;
    211 using ::fread;
    212 using ::fwrite;
    213 using ::fgetpos;
    214 using ::fseek;
    215 using ::fsetpos;
    216 using ::ftell;
    217 using ::rewind;
    218 using ::clearerr;
    219 using ::feof;
    220 using ::ferror;
    221 using ::perror;
    222 
    223 _LIBCPP_END_NAMESPACE_STD
    224 
    225 #endif  // _LIBCPP_CSTDIO
    226