1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // test <stdio.h>
10 
11 #include <stdio.h>
12 #include <type_traits>
13 #include "test_macros.h"
14 
15 #ifdef getc
16 #error getc is defined
17 #endif
18 
19 #ifdef putc
20 #error putc is defined
21 #endif
22 
23 #ifdef clearerr
24 #error clearerr is defined
25 #endif
26 
27 #ifdef feof
28 #error feof is defined
29 #endif
30 
31 #ifdef ferror
32 #error ferror is defined
33 #endif
34 
35 #ifndef BUFSIZ
36 #error BUFSIZ not defined
37 #endif
38 
39 #ifndef EOF
40 #error EOF not defined
41 #endif
42 
43 #ifndef FILENAME_MAX
44 #error FILENAME_MAX not defined
45 #endif
46 
47 #ifndef FOPEN_MAX
48 #error FOPEN_MAX not defined
49 #endif
50 
51 #ifndef L_tmpnam
52 #error L_tmpnam not defined
53 #endif
54 
55 #ifndef NULL
56 #error NULL not defined
57 #endif
58 
59 #ifndef SEEK_CUR
60 #error SEEK_CUR not defined
61 #endif
62 
63 #ifndef SEEK_END
64 #error SEEK_END not defined
65 #endif
66 
67 #ifndef SEEK_SET
68 #error SEEK_SET not defined
69 #endif
70 
71 #ifndef TMP_MAX
72 #error TMP_MAX not defined
73 #endif
74 
75 #ifndef _IOFBF
76 #error _IOFBF not defined
77 #endif
78 
79 #ifndef _IOLBF
80 #error _IOLBF not defined
81 #endif
82 
83 #ifndef _IONBF
84 #error _IONBF not defined
85 #endif
86 
87 #ifndef stderr
88 #error stderr not defined
89 #endif
90 
91 #ifndef stdin
92 #error stdin not defined
93 #endif
94 
95 #ifndef stdout
96 #error stdout not defined
97 #endif
98 
99 #include <cstdarg>
100 
101 #if defined(__GNUC__) || defined(__clang__)
102 #pragma GCC diagnostic ignored "-Wformat-zero-length"
103 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // for tmpnam
104 #endif
105 
106 int main(int, char**)
107 {
108     FILE* fp = 0;
109     fpos_t fpos = fpos_t();
110     size_t s = 0;
111     char* cp = 0;
112     char arr[] = {'a', 'b'};
113     va_list va;
114     ((void)fp); // Prevent unused warning
115     ((void)fpos); // Prevent unused warning
116     ((void)s); // Prevent unused warning
117     ((void)cp); // Prevent unused warning
118     ((void)arr); // Prevent unused warning
119     ((void)va); // Prevent unused warning
120     static_assert((std::is_same<decltype(remove("")), int>::value), "");
121     static_assert((std::is_same<decltype(rename("","")), int>::value), "");
122     static_assert((std::is_same<decltype(tmpfile()), FILE*>::value), "");
123     static_assert((std::is_same<decltype(tmpnam(cp)), char*>::value), "");
124     static_assert((std::is_same<decltype(fclose(fp)), int>::value), "");
125     static_assert((std::is_same<decltype(fflush(fp)), int>::value), "");
126     static_assert((std::is_same<decltype(fopen("", "")), FILE*>::value), "");
127     static_assert((std::is_same<decltype(freopen("", "", fp)), FILE*>::value), "");
128     static_assert((std::is_same<decltype(setbuf(fp,cp)), void>::value), "");
129     static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), "");
130     static_assert((std::is_same<decltype(fprintf(fp," ")), int>::value), "");
131     static_assert((std::is_same<decltype(fscanf(fp,"")), int>::value), "");
132     static_assert((std::is_same<decltype(printf("\n")), int>::value), "");
133     static_assert((std::is_same<decltype(scanf("\n")), int>::value), "");
134     static_assert((std::is_same<decltype(snprintf(cp,0,"p")), int>::value), "");
135     static_assert((std::is_same<decltype(sprintf(cp," ")), int>::value), "");
136     static_assert((std::is_same<decltype(sscanf("","")), int>::value), "");
137     static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), "");
138     static_assert((std::is_same<decltype(vfscanf(fp,"",va)), int>::value), "");
139     static_assert((std::is_same<decltype(vprintf(" ",va)), int>::value), "");
140     static_assert((std::is_same<decltype(vscanf("",va)), int>::value), "");
141     static_assert((std::is_same<decltype(vsnprintf(cp,0," ",va)), int>::value), "");
142     static_assert((std::is_same<decltype(vsprintf(cp," ",va)), int>::value), "");
143     static_assert((std::is_same<decltype(vsscanf("","",va)), int>::value), "");
144     static_assert((std::is_same<decltype(fgetc(fp)), int>::value), "");
145     static_assert((std::is_same<decltype(fgets(cp,0,fp)), char*>::value), "");
146     static_assert((std::is_same<decltype(fputc(0,fp)), int>::value), "");
147     static_assert((std::is_same<decltype(fputs("",fp)), int>::value), "");
148     static_assert((std::is_same<decltype(getc(fp)), int>::value), "");
149     static_assert((std::is_same<decltype(getchar()), int>::value), "");
150 #if TEST_STD_VER < 14
151     static_assert((std::is_same<decltype(gets(cp)), char*>::value), "");
152 #endif
153     static_assert((std::is_same<decltype(putc(0,fp)), int>::value), "");
154     static_assert((std::is_same<decltype(putchar(0)), int>::value), "");
155     static_assert((std::is_same<decltype(puts("")), int>::value), "");
156     static_assert((std::is_same<decltype(ungetc(0,fp)), int>::value), "");
157     static_assert((std::is_same<decltype(fread((void*)0,0,0,fp)), size_t>::value), "");
158     static_assert((std::is_same<decltype(fwrite((const void*)arr,1,0,fp)), size_t>::value), "");
159 #ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
160     static_assert((std::is_same<decltype(fgetpos(fp, &fpos)), int>::value), "");
161 #endif
162     static_assert((std::is_same<decltype(fseek(fp, 0,0)), int>::value), "");
163 #ifndef _LIBCPP_HAS_NO_FGETPOS_FSETPOS
164     static_assert((std::is_same<decltype(fsetpos(fp, &fpos)), int>::value), "");
165 #endif
166     static_assert((std::is_same<decltype(ftell(fp)), long>::value), "");
167     static_assert((std::is_same<decltype(rewind(fp)), void>::value), "");
168     static_assert((std::is_same<decltype(clearerr(fp)), void>::value), "");
169     static_assert((std::is_same<decltype(feof(fp)), int>::value), "");
170     static_assert((std::is_same<decltype(ferror(fp)), int>::value), "");
171     static_assert((std::is_same<decltype(perror("")), void>::value), "");
172 
173   return 0;
174 }
175