libcxx: Provide overloads for basic_filebuf::open() et al that take wchar_t* filenames on Windows.
This is an MSVC standard library extension. It seems like a reasonable enough extension to me because wchar_t* is the native format for filenames on that platform. Differential Revision: https://reviews.llvm.org/D42225 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@323170 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <fstream>
|
||||
|
||||
// template <class charT, class traits = char_traits<charT> >
|
||||
// class basic_fstream
|
||||
|
||||
// explicit basic_fstream(const wchar_t* s, ios_base::openmode mode = ios_base::in | ios_base::out);
|
||||
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include "platform_support.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
|
||||
std::wstring temp = get_wide_temp_file_name();
|
||||
{
|
||||
std::fstream fs(temp.c_str(), std::ios_base::in | std::ios_base::out
|
||||
| std::ios_base::trunc);
|
||||
double x = 0;
|
||||
fs << 3.25;
|
||||
fs.seekg(0);
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
{
|
||||
std::wfstream fs(temp.c_str(), std::ios_base::in | std::ios_base::out
|
||||
| std::ios_base::trunc);
|
||||
double x = 0;
|
||||
fs << 3.25;
|
||||
fs.seekg(0);
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <fstream>
|
||||
|
||||
// template <class charT, class traits = char_traits<charT> >
|
||||
// class basic_fstream
|
||||
|
||||
// void open(const wchar_t* s, ios_base::openmode mode = ios_base::in|ios_base::out);
|
||||
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include "platform_support.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
|
||||
std::wstring temp = get_wide_temp_file_name();
|
||||
{
|
||||
std::fstream fs;
|
||||
assert(!fs.is_open());
|
||||
fs.open(temp.c_str(), std::ios_base::in | std::ios_base::out
|
||||
| std::ios_base::trunc);
|
||||
assert(fs.is_open());
|
||||
double x = 0;
|
||||
fs << 3.25;
|
||||
fs.seekg(0);
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
{
|
||||
std::wfstream fs;
|
||||
assert(!fs.is_open());
|
||||
fs.open(temp.c_str(), std::ios_base::in | std::ios_base::out
|
||||
| std::ios_base::trunc);
|
||||
assert(fs.is_open());
|
||||
double x = 0;
|
||||
fs << 3.25;
|
||||
fs.seekg(0);
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
3.25
|
||||
@@ -0,0 +1,42 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <fstream>
|
||||
|
||||
// template <class charT, class traits = char_traits<charT> >
|
||||
// class basic_ifstream
|
||||
|
||||
// explicit basic_ifstream(const wchar_t* s, ios_base::openmode mode = ios_base::in);
|
||||
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
|
||||
{
|
||||
std::ifstream fs(L"test.dat");
|
||||
double x = 0;
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
// std::ifstream(const wchar_t*, std::ios_base::openmode) is tested in
|
||||
// test/libcxx/input.output/file.streams/fstreams/ofstream.cons/wchar_pointer.pass.cpp
|
||||
// which creates writable files.
|
||||
{
|
||||
std::wifstream fs(L"test.dat");
|
||||
double x = 0;
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
// std::wifstream(const wchar_t*, std::ios_base::openmode) is tested in
|
||||
// test/libcxx/input.output/file.streams/fstreams/ofstream.cons/wchar_pointer.pass.cpp
|
||||
// which creates writable files.
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <fstream>
|
||||
|
||||
// template <class charT, class traits = char_traits<charT> >
|
||||
// class basic_ifstream
|
||||
|
||||
// void open(const wchar_t* s, ios_base::openmode mode = ios_base::in);
|
||||
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
|
||||
{
|
||||
std::ifstream fs;
|
||||
assert(!fs.is_open());
|
||||
char c = 'a';
|
||||
fs >> c;
|
||||
assert(fs.fail());
|
||||
assert(c == 'a');
|
||||
fs.open(L"test.dat");
|
||||
assert(fs.is_open());
|
||||
fs >> c;
|
||||
assert(c == 'r');
|
||||
}
|
||||
{
|
||||
std::wifstream fs;
|
||||
assert(!fs.is_open());
|
||||
wchar_t c = L'a';
|
||||
fs >> c;
|
||||
assert(fs.fail());
|
||||
assert(c == L'a');
|
||||
fs.open(L"test.dat");
|
||||
assert(fs.is_open());
|
||||
fs >> c;
|
||||
assert(c == L'r');
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
r
|
||||
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <fstream>
|
||||
|
||||
// template <class charT, class traits = char_traits<charT> >
|
||||
// class basic_ofstream
|
||||
|
||||
// explicit basic_ofstream(const wchar_t* s, ios_base::openmode mode = ios_base::out);
|
||||
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include "platform_support.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
|
||||
std::wstring temp = get_wide_temp_file_name();
|
||||
{
|
||||
std::ofstream fs(temp.c_str());
|
||||
fs << 3.25;
|
||||
}
|
||||
{
|
||||
std::ifstream fs(temp.c_str());
|
||||
double x = 0;
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
{
|
||||
std::ifstream fs(temp.c_str(), std::ios_base::out);
|
||||
double x = 0;
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
{
|
||||
std::wofstream fs(temp.c_str());
|
||||
fs << 3.25;
|
||||
}
|
||||
{
|
||||
std::wifstream fs(temp.c_str());
|
||||
double x = 0;
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
{
|
||||
std::wifstream fs(temp.c_str(), std::ios_base::out);
|
||||
double x = 0;
|
||||
fs >> x;
|
||||
assert(x == 3.25);
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <fstream>
|
||||
|
||||
// template <class charT, class traits = char_traits<charT> >
|
||||
// class basic_ofstream
|
||||
|
||||
// void open(const wchar_t* s, ios_base::openmode mode = ios_base::out);
|
||||
|
||||
#include <fstream>
|
||||
#include <cassert>
|
||||
#include "platform_support.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
|
||||
std::wstring temp = get_wide_temp_file_name();
|
||||
{
|
||||
std::ofstream fs;
|
||||
assert(!fs.is_open());
|
||||
char c = 'a';
|
||||
fs << c;
|
||||
assert(fs.fail());
|
||||
fs.open(temp.c_str());
|
||||
assert(fs.is_open());
|
||||
fs << c;
|
||||
}
|
||||
{
|
||||
std::ifstream fs(temp.c_str());
|
||||
char c = 0;
|
||||
fs >> c;
|
||||
assert(c == 'a');
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
{
|
||||
std::wofstream fs;
|
||||
assert(!fs.is_open());
|
||||
wchar_t c = L'a';
|
||||
fs << c;
|
||||
assert(fs.fail());
|
||||
fs.open(temp.c_str());
|
||||
assert(fs.is_open());
|
||||
fs << c;
|
||||
}
|
||||
{
|
||||
std::wifstream fs(temp.c_str());
|
||||
wchar_t c = 0;
|
||||
fs >> c;
|
||||
assert(c == L'a');
|
||||
}
|
||||
_wremove(temp.c_str());
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user