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 // <fstream>
10 
11 // basic_filebuf<charT,traits>* open(const char* s, ios_base::openmode mode);
12 
13 #include <fstream>
14 #include <cassert>
15 #include "platform_support.h"
16 
17 int main(int, char**)
18 {
19     std::string temp = get_temp_file_name();
20     {
21         std::filebuf f;
22         assert(f.open(temp.c_str(), std::ios_base::out) != 0);
23         assert(f.is_open());
24         assert(f.sputn("123", 3) == 3);
25     }
26     {
27         std::filebuf f;
28         assert(f.open(temp.c_str(), std::ios_base::in) != 0);
29         assert(f.is_open());
30         assert(f.sbumpc() == '1');
31         assert(f.sbumpc() == '2');
32         assert(f.sbumpc() == '3');
33     }
34     std::remove(temp.c_str());
35     {
36         std::wfilebuf f;
37         assert(f.open(temp.c_str(), std::ios_base::out) != 0);
38         assert(f.is_open());
39         assert(f.sputn(L"123", 3) == 3);
40     }
41     {
42         std::wfilebuf f;
43         assert(f.open(temp.c_str(), std::ios_base::in) != 0);
44         assert(f.is_open());
45         assert(f.sbumpc() == L'1');
46         assert(f.sbumpc() == L'2');
47         assert(f.sbumpc() == L'3');
48     }
49     remove(temp.c_str());
50 
51   return 0;
52 }
53