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 <cstdio>
10
11#include <cstdio>
12#include <type_traits>
13
14#include "test_macros.h"
15
16#ifndef BUFSIZ
17#error BUFSIZ not defined
18#endif
19
20#ifndef EOF
21#error EOF not defined
22#endif
23
24#ifndef FILENAME_MAX
25#error FILENAME_MAX not defined
26#endif
27
28#ifndef FOPEN_MAX
29#error FOPEN_MAX not defined
30#endif
31
32#ifndef L_tmpnam
33#error L_tmpnam not defined
34#endif
35
36#ifndef NULL
37#error NULL not defined
38#endif
39
40#ifndef SEEK_CUR
41#error SEEK_CUR not defined
42#endif
43
44#ifndef SEEK_END
45#error SEEK_END not defined
46#endif
47
48#ifndef SEEK_SET
49#error SEEK_SET not defined
50#endif
51
52#ifndef TMP_MAX
53#error TMP_MAX not defined
54#endif
55
56#ifndef _IOFBF
57#error _IOFBF not defined
58#endif
59
60#ifndef _IOLBF
61#error _IOLBF not defined
62#endif
63
64#ifndef _IONBF
65#error _IONBF not defined
66#endif
67
68#ifndef stderr
69#error stderr not defined
70#endif
71
72#ifndef stdin
73#error stdin not defined
74#endif
75
76#ifndef stdout
77#error stdout not defined
78#endif
79
80#include <cstdarg>
81
82TEST_CLANG_DIAGNOSTIC_IGNORED("-Wformat-zero-length")
83
84int main(int, char**)
85{
86 std::FILE* fp = 0;
87 std::fpos_t fpos = std::fpos_t();
88 std::size_t s = 0;
89 char* cp = 0;
90 std::va_list va;
91 void const* vp = 0;
92 ((void)fp); // Prevent unused warning
93 ((void)fpos); // Prevent unused warning
94 ((void)s); // Prevent unused warning
95 ((void)cp); // Prevent unused warning
96 ((void)va); // Prevent unused warning
97 ((void)vp); // Prevent unused warning
98 static_assert((std::is_same<decltype(std::fclose(stream: fp)), int>::value), "");
99 static_assert((std::is_same<decltype(std::fflush(stream: fp)), int>::value), "");
100 static_assert((std::is_same<decltype(std::setbuf(stream: fp,buf: cp)), void>::value), "");
101 static_assert((std::is_same<decltype(std::vfprintf(s: fp,format: " ",arg: va)), int>::value), "");
102 static_assert((std::is_same<decltype(std::fprintf(stream: fp,format: " ")), int>::value), "");
103 static_assert((std::is_same<decltype(std::fscanf(stream: fp,format: " ")), int>::value), "");
104 static_assert((std::is_same<decltype(std::snprintf(s: cp,maxlen: 0,format: " ")), int>::value), "");
105 TEST_DIAGNOSTIC_PUSH
106 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
107 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
108 static_assert((std::is_same<decltype(std::sprintf(cp," ")), int>::value), "");
109 TEST_DIAGNOSTIC_POP
110 static_assert((std::is_same<decltype(std::sscanf(""," ")), int>::value), "");
111 static_assert((std::is_same<decltype(std::vfprintf(s: fp,format: " ",arg: va)), int>::value), "");
112 static_assert((std::is_same<decltype(std::vfscanf(s: fp,format: " ",arg: va)), int>::value), "");
113 static_assert((std::is_same<decltype(std::vsnprintf(s: cp,maxlen: 0,format: " ",arg: va)), int>::value), "");
114 TEST_DIAGNOSTIC_PUSH
115 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
116 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
117 static_assert((std::is_same<decltype(std::vsprintf(cp," ",va)), int>::value), "");
118 TEST_DIAGNOSTIC_POP
119 static_assert((std::is_same<decltype(std::vsscanf(""," ",va)), int>::value), "");
120 static_assert((std::is_same<decltype(std::fgetc(stream: fp)), int>::value), "");
121 static_assert((std::is_same<decltype(std::fgets(s: cp,n: 0,stream: fp)), char*>::value), "");
122 static_assert((std::is_same<decltype(std::fputc(c: 0,stream: fp)), int>::value), "");
123 static_assert((std::is_same<decltype(std::fputs(s: "",stream: fp)), int>::value), "");
124 static_assert((std::is_same<decltype(std::getc(stream: fp)), int>::value), "");
125 static_assert((std::is_same<decltype(std::putc(c: 0,stream: fp)), int>::value), "");
126 static_assert((std::is_same<decltype(std::ungetc(c: 0,stream: fp)), int>::value), "");
127 static_assert((std::is_same<decltype(std::fread(ptr: (void*)0,size: 0,n: 0,stream: fp)), std::size_t>::value), "");
128 static_assert((std::is_same<decltype(std::fwrite(ptr: vp,size: 0,n: 0,s: fp)), std::size_t>::value), "");
129 static_assert((std::is_same<decltype(std::fgetpos(stream: fp, pos: &fpos)), int>::value), "");
130 static_assert((std::is_same<decltype(std::fseek(stream: fp, off: 0,whence: 0)), int>::value), "");
131 static_assert((std::is_same<decltype(std::fsetpos(stream: fp, pos: &fpos)), int>::value), "");
132 static_assert((std::is_same<decltype(std::ftell(stream: fp)), long>::value), "");
133 static_assert((std::is_same<decltype(std::rewind(stream: fp)), void>::value), "");
134 static_assert((std::is_same<decltype(std::clearerr(stream: fp)), void>::value), "");
135 static_assert((std::is_same<decltype(std::feof(stream: fp)), int>::value), "");
136 static_assert((std::is_same<decltype(std::ferror(stream: fp)), int>::value), "");
137 static_assert((std::is_same<decltype(std::perror(s: "")), void>::value), "");
138
139 static_assert((std::is_same<decltype(std::fopen(filename: "", modes: "")), std::FILE*>::value), "");
140 static_assert((std::is_same<decltype(std::freopen(filename: "", modes: "", stream: fp)), std::FILE*>::value), "");
141 static_assert((std::is_same<decltype(std::remove(filename: "")), int>::value), "");
142 static_assert((std::is_same<decltype(std::rename(old: "",new: "")), int>::value), "");
143 static_assert((std::is_same<decltype(std::tmpfile()), std::FILE*>::value), "");
144
145 TEST_DIAGNOSTIC_PUSH
146 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
147 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
148 static_assert((std::is_same<decltype(std::tmpnam(cp)), char*>::value), "");
149 TEST_DIAGNOSTIC_POP
150
151 static_assert((std::is_same<decltype(std::getchar()), int>::value), "");
152#if TEST_STD_VER <= 11
153 TEST_DIAGNOSTIC_PUSH
154 TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
155 TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
156 static_assert((std::is_same<decltype(std::gets(cp)), char*>::value), "");
157 TEST_DIAGNOSTIC_POP
158#endif
159 static_assert((std::is_same<decltype(std::scanf(" ")), int>::value), "");
160 static_assert((std::is_same<decltype(std::vscanf(format: " ",arg: va)), int>::value), "");
161
162 static_assert((std::is_same<decltype(std::printf(format: " ")), int>::value), "");
163 static_assert((std::is_same<decltype(std::putchar(c: 0)), int>::value), "");
164 static_assert((std::is_same<decltype(std::puts(s: "")), int>::value), "");
165 static_assert((std::is_same<decltype(std::vprintf(format: " ",arg: va)), int>::value), "");
166
167 return 0;
168}
169

source code of libcxx/test/std/input.output/file.streams/c.files/cstdio.pass.cpp