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 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
102 TEST_GCC_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
103 
main(int,char **)104 int main(int, char**)
105 {
106     FILE* fp = 0;
107     fpos_t fpos = fpos_t();
108     size_t s = 0;
109     char* cp = 0;
110     char arr[] = {'a', 'b'};
111     va_list va;
112     ((void)fp); // Prevent unused warning
113     ((void)fpos); // Prevent unused warning
114     ((void)s); // Prevent unused warning
115     ((void)cp); // Prevent unused warning
116     ((void)arr); // Prevent unused warning
117     ((void)va); // Prevent unused warning
118     static_assert((std::is_same<decltype(remove("")), int>::value), "");
119     static_assert((std::is_same<decltype(rename("","")), int>::value), "");
120     static_assert((std::is_same<decltype(tmpfile()), FILE*>::value), "");
121     TEST_DIAGNOSTIC_PUSH
122     TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
123     TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
124     static_assert((std::is_same<decltype(tmpnam(cp)), char*>::value), "");
125     TEST_DIAGNOSTIC_POP
126     static_assert((std::is_same<decltype(fclose(fp)), int>::value), "");
127     static_assert((std::is_same<decltype(fflush(fp)), int>::value), "");
128     static_assert((std::is_same<decltype(fopen("", "")), FILE*>::value), "");
129     static_assert((std::is_same<decltype(freopen("", "", fp)), FILE*>::value), "");
130     static_assert((std::is_same<decltype(setbuf(fp,cp)), void>::value), "");
131     static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), "");
132     static_assert((std::is_same<decltype(fprintf(fp," ")), int>::value), "");
133     static_assert((std::is_same<decltype(fscanf(fp,"")), int>::value), "");
134     static_assert((std::is_same<decltype(printf("\n")), int>::value), "");
135     static_assert((std::is_same<decltype(scanf("\n")), int>::value), "");
136     static_assert((std::is_same<decltype(snprintf(cp,0,"p")), int>::value), "");
137     TEST_DIAGNOSTIC_PUSH
138     TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
139     TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
140     static_assert((std::is_same<decltype(sprintf(cp," ")), int>::value), "");
141     TEST_DIAGNOSTIC_POP
142     static_assert((std::is_same<decltype(sscanf("","")), int>::value), "");
143     static_assert((std::is_same<decltype(vfprintf(fp,"",va)), int>::value), "");
144     static_assert((std::is_same<decltype(vfscanf(fp,"",va)), int>::value), "");
145     static_assert((std::is_same<decltype(vprintf(" ",va)), int>::value), "");
146     static_assert((std::is_same<decltype(vscanf("",va)), int>::value), "");
147     static_assert((std::is_same<decltype(vsnprintf(cp,0," ",va)), int>::value), "");
148     TEST_DIAGNOSTIC_PUSH
149     TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
150     TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
151     static_assert((std::is_same<decltype(vsprintf(cp," ",va)), int>::value), "");
152     TEST_DIAGNOSTIC_POP
153     static_assert((std::is_same<decltype(vsscanf("","",va)), int>::value), "");
154     static_assert((std::is_same<decltype(fgetc(fp)), int>::value), "");
155     static_assert((std::is_same<decltype(fgets(cp,0,fp)), char*>::value), "");
156     static_assert((std::is_same<decltype(fputc(0,fp)), int>::value), "");
157     static_assert((std::is_same<decltype(fputs("",fp)), int>::value), "");
158     static_assert((std::is_same<decltype(getc(fp)), int>::value), "");
159     static_assert((std::is_same<decltype(getchar()), int>::value), "");
160 #if TEST_STD_VER < 14
161     TEST_DIAGNOSTIC_PUSH
162     TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
163     TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
164     static_assert((std::is_same<decltype(gets(cp)), char*>::value), "");
165     TEST_DIAGNOSTIC_POP
166 #endif
167     static_assert((std::is_same<decltype(putc(0,fp)), int>::value), "");
168     static_assert((std::is_same<decltype(putchar(0)), int>::value), "");
169     static_assert((std::is_same<decltype(puts("")), int>::value), "");
170     static_assert((std::is_same<decltype(ungetc(0,fp)), int>::value), "");
171     static_assert((std::is_same<decltype(fread((void*)0,0,0,fp)), size_t>::value), "");
172     static_assert((std::is_same<decltype(fwrite((const void*)arr,1,0,fp)), size_t>::value), "");
173 #ifndef TEST_HAS_NO_FGETPOS_FSETPOS
174     static_assert((std::is_same<decltype(fgetpos(fp, &fpos)), int>::value), "");
175 #endif
176     static_assert((std::is_same<decltype(fseek(fp, 0,0)), int>::value), "");
177 #ifndef TEST_HAS_NO_FGETPOS_FSETPOS
178     static_assert((std::is_same<decltype(fsetpos(fp, &fpos)), int>::value), "");
179 #endif
180     static_assert((std::is_same<decltype(ftell(fp)), long>::value), "");
181     static_assert((std::is_same<decltype(rewind(fp)), void>::value), "");
182     static_assert((std::is_same<decltype(clearerr(fp)), void>::value), "");
183     static_assert((std::is_same<decltype(feof(fp)), int>::value), "");
184     static_assert((std::is_same<decltype(ferror(fp)), int>::value), "");
185     static_assert((std::is_same<decltype(perror("")), void>::value), "");
186 
187   return 0;
188 }
189