From 06d8bf6ce2008526732ae40ad46f7ff031c409e7 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 22 Mar 2013 20:05:40 +0000 Subject: [PATCH] Test cleanup with respect to use of deprecated tmpnam function. Also Windows port for these tests to use _tempnam. The bulk of this patch was donated anonymously. I've tested it on OS X and accept responsibility for it. If I've broken anyone's platform by switching from tmpnam to mktemp for the generation of temporary file names, just let me know. Should be easy to fix in test/support/platform_support.h git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@177755 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../filebuf.assign/member_swap.pass.cpp | 12 ++++---- .../filebuf.assign/move_assign.pass.cpp | 12 ++++---- .../filebuf.assign/nonmember_swap.pass.cpp | 12 ++++---- .../fstreams/filebuf.cons/move.pass.cpp | 12 ++++---- .../filebuf.members/open_pointer.pass.cpp | 16 +++++----- .../fstream.assign/member_swap.pass.cpp | 22 +++++++------- .../fstream.assign/move_assign.pass.cpp | 12 ++++---- .../fstream.assign/nonmember_swap.pass.cpp | 22 +++++++------- .../fstreams/fstream.cons/move.pass.cpp | 8 ++--- .../fstreams/fstream.cons/pointer.pass.cpp | 12 ++++---- .../fstreams/fstream.cons/string.pass.cpp | 12 ++++---- .../fstreams/fstream.members/close.pass.cpp | 12 ++++---- .../fstream.members/open_pointer.pass.cpp | 12 ++++---- .../fstream.members/open_string.pass.cpp | 12 ++++---- .../ofstream.assign/member_swap.pass.cpp | 30 +++++++++---------- .../ofstream.assign/move_assign.pass.cpp | 16 +++++----- .../ofstream.assign/nonmember_swap.pass.cpp | 30 +++++++++---------- .../fstreams/ofstream.cons/move.pass.cpp | 16 +++++----- .../fstreams/ofstream.cons/pointer.pass.cpp | 16 +++++----- .../fstreams/ofstream.cons/string.pass.cpp | 16 +++++----- .../fstreams/ofstream.members/close.pass.cpp | 12 ++++---- .../ofstream.members/open_pointer.pass.cpp | 16 +++++----- .../ofstream.members/open_string.pass.cpp | 16 +++++----- .../fstreams/ofstream.members/rdbuf.pass.cpp | 12 ++++---- test/support/platform_support.h | 21 +++++++++++++ 25 files changed, 205 insertions(+), 184 deletions(-) diff --git a/test/input.output/file.streams/fstreams/filebuf.assign/member_swap.pass.cpp b/test/input.output/file.streams/fstreams/filebuf.assign/member_swap.pass.cpp index 10aa05d45..86844343e 100644 --- a/test/input.output/file.streams/fstreams/filebuf.assign/member_swap.pass.cpp +++ b/test/input.output/file.streams/fstreams/filebuf.assign/member_swap.pass.cpp @@ -16,14 +16,14 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::filebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn("123", 3) == 3); @@ -35,10 +35,10 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == '2'); } - remove(temp); + std::remove(temp.c_str()); { std::wfilebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn(L"123", 3) == 3); @@ -50,5 +50,5 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == L'2'); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/filebuf.assign/move_assign.pass.cpp b/test/input.output/file.streams/fstreams/filebuf.assign/move_assign.pass.cpp index 739f99480..a92ec872a 100644 --- a/test/input.output/file.streams/fstreams/filebuf.assign/move_assign.pass.cpp +++ b/test/input.output/file.streams/fstreams/filebuf.assign/move_assign.pass.cpp @@ -16,15 +16,15 @@ #include #include +#include "platform_support.h" int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::filebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn("123", 3) == 3); @@ -36,10 +36,10 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == '2'); } - remove(temp); + std::remove(temp.c_str()); { std::wfilebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn(L"123", 3) == 3); @@ -51,6 +51,6 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == L'2'); } - remove(temp); + std::remove(temp.c_str()); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/input.output/file.streams/fstreams/filebuf.assign/nonmember_swap.pass.cpp b/test/input.output/file.streams/fstreams/filebuf.assign/nonmember_swap.pass.cpp index 9a9b28ce4..084d00103 100644 --- a/test/input.output/file.streams/fstreams/filebuf.assign/nonmember_swap.pass.cpp +++ b/test/input.output/file.streams/fstreams/filebuf.assign/nonmember_swap.pass.cpp @@ -18,14 +18,14 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::filebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn("123", 3) == 3); @@ -37,10 +37,10 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == '2'); } - remove(temp); + std::remove(temp.c_str()); { std::wfilebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn(L"123", 3) == 3); @@ -52,5 +52,5 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == L'2'); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/filebuf.cons/move.pass.cpp b/test/input.output/file.streams/fstreams/filebuf.cons/move.pass.cpp index 352a98091..f13ee4470 100644 --- a/test/input.output/file.streams/fstreams/filebuf.cons/move.pass.cpp +++ b/test/input.output/file.streams/fstreams/filebuf.cons/move.pass.cpp @@ -16,15 +16,15 @@ #include #include +#include "platform_support.h" int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::filebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn("123", 3) == 3); @@ -35,10 +35,10 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == '2'); } - remove(temp); + std::remove(temp.c_str()); { std::wfilebuf f; - assert(f.open(temp, std::ios_base::out | std::ios_base::in + assert(f.open(temp.c_str(), std::ios_base::out | std::ios_base::in | std::ios_base::trunc) != 0); assert(f.is_open()); assert(f.sputn(L"123", 3) == 3); @@ -49,6 +49,6 @@ int main() assert(f2.is_open()); assert(f2.sgetc() == L'2'); } - remove(temp); + std::remove(temp.c_str()); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/input.output/file.streams/fstreams/filebuf.members/open_pointer.pass.cpp b/test/input.output/file.streams/fstreams/filebuf.members/open_pointer.pass.cpp index 192e65f55..9d2d56782 100644 --- a/test/input.output/file.streams/fstreams/filebuf.members/open_pointer.pass.cpp +++ b/test/input.output/file.streams/fstreams/filebuf.members/open_pointer.pass.cpp @@ -13,39 +13,39 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::filebuf f; - assert(f.open(temp, std::ios_base::out) != 0); + assert(f.open(temp.c_str(), std::ios_base::out) != 0); assert(f.is_open()); assert(f.sputn("123", 3) == 3); } { std::filebuf f; - assert(f.open(temp, std::ios_base::in) != 0); + assert(f.open(temp.c_str(), std::ios_base::in) != 0); assert(f.is_open()); assert(f.sbumpc() == '1'); assert(f.sbumpc() == '2'); assert(f.sbumpc() == '3'); } - remove(temp); + std::remove(temp.c_str()); { std::wfilebuf f; - assert(f.open(temp, std::ios_base::out) != 0); + assert(f.open(temp.c_str(), std::ios_base::out) != 0); assert(f.is_open()); assert(f.sputn(L"123", 3) == 3); } { std::wfilebuf f; - assert(f.open(temp, std::ios_base::in) != 0); + assert(f.open(temp.c_str(), std::ios_base::in) != 0); assert(f.is_open()); assert(f.sbumpc() == L'1'); assert(f.sbumpc() == L'2'); assert(f.sbumpc() == L'3'); } - remove(temp); + remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/fstream.assign/member_swap.pass.cpp b/test/input.output/file.streams/fstreams/fstream.assign/member_swap.pass.cpp index 4cae835ea..fcc86a13f 100644 --- a/test/input.output/file.streams/fstreams/fstream.assign/member_swap.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.assign/member_swap.pass.cpp @@ -16,16 +16,16 @@ #include #include +#include "platform_support.h" int main() { - char temp1[L_tmpnam], temp2[L_tmpnam]; - tmpnam(temp1); - tmpnam(temp2); + std::string temp1 = get_temp_file_name(); + std::string temp2 = get_temp_file_name(); { - std::fstream fs1(temp1, std::ios_base::in | std::ios_base::out + std::fstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); - std::fstream fs2(temp2, std::ios_base::in | std::ios_base::out + std::fstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; @@ -43,12 +43,12 @@ int main() fs2 >> i; assert(i == 2); } - std::remove(temp1); - std::remove(temp2); + std::remove(temp1.c_str()); + std::remove(temp2.c_str()); { - std::wfstream fs1(temp1, std::ios_base::in | std::ios_base::out + std::wfstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); - std::wfstream fs2(temp2, std::ios_base::in | std::ios_base::out + std::wfstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; @@ -66,6 +66,6 @@ int main() fs2 >> i; assert(i == 2); } - std::remove(temp1); - std::remove(temp2); + std::remove(temp1.c_str()); + std::remove(temp2.c_str()); } diff --git a/test/input.output/file.streams/fstreams/fstream.assign/move_assign.pass.cpp b/test/input.output/file.streams/fstreams/fstream.assign/move_assign.pass.cpp index 51cf41fdf..b5157e90e 100644 --- a/test/input.output/file.streams/fstreams/fstream.assign/move_assign.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.assign/move_assign.pass.cpp @@ -16,14 +16,14 @@ #include #include +#include "platform_support.h" int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::fstream fso(temp, std::ios_base::in | std::ios_base::out + std::fstream fso(temp.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::fstream fs; fs = move(fso); @@ -33,9 +33,9 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); { - std::wfstream fso(temp, std::ios_base::in | std::ios_base::out + std::wfstream fso(temp.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::wfstream fs; fs = move(fso); @@ -45,6 +45,6 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/input.output/file.streams/fstreams/fstream.assign/nonmember_swap.pass.cpp b/test/input.output/file.streams/fstreams/fstream.assign/nonmember_swap.pass.cpp index 27ee8427f..0a4f7240d 100644 --- a/test/input.output/file.streams/fstreams/fstream.assign/nonmember_swap.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.assign/nonmember_swap.pass.cpp @@ -17,16 +17,16 @@ #include #include +#include "platform_support.h" int main() { - char temp1[L_tmpnam], temp2[L_tmpnam]; - tmpnam(temp1); - tmpnam(temp2); + std::string temp1 = get_temp_file_name(); + std::string temp2 = get_temp_file_name(); { - std::fstream fs1(temp1, std::ios_base::in | std::ios_base::out + std::fstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); - std::fstream fs2(temp2, std::ios_base::in | std::ios_base::out + std::fstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; @@ -44,12 +44,12 @@ int main() fs2 >> i; assert(i == 2); } - std::remove(temp1); - std::remove(temp2); + std::remove(temp1.c_str()); + std::remove(temp2.c_str()); { - std::wfstream fs1(temp1, std::ios_base::in | std::ios_base::out + std::wfstream fs1(temp1.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); - std::wfstream fs2(temp2, std::ios_base::in | std::ios_base::out + std::wfstream fs2(temp2.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); fs1 << 1 << ' ' << 2; fs2 << 2 << ' ' << 1; @@ -67,6 +67,6 @@ int main() fs2 >> i; assert(i == 2); } - std::remove(temp1); - std::remove(temp2); + std::remove(temp1.c_str()); + std::remove(temp2.c_str()); } diff --git a/test/input.output/file.streams/fstreams/fstream.cons/move.pass.cpp b/test/input.output/file.streams/fstreams/fstream.cons/move.pass.cpp index 28e3c95d4..d2ae30286 100644 --- a/test/input.output/file.streams/fstreams/fstream.cons/move.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.cons/move.pass.cpp @@ -16,12 +16,12 @@ #include #include +#include "platform_support.h" int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::fstream fso(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); @@ -32,7 +32,7 @@ int main() fs >> x; assert(x == 3.25); } - std::remove("test.dat"); + std::remove(temp.c_str()); { std::wfstream fso(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); @@ -43,6 +43,6 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/input.output/file.streams/fstreams/fstream.cons/pointer.pass.cpp b/test/input.output/file.streams/fstreams/fstream.cons/pointer.pass.cpp index a31f9a1d5..06a6b7794 100644 --- a/test/input.output/file.streams/fstreams/fstream.cons/pointer.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.cons/pointer.pass.cpp @@ -16,13 +16,13 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::fstream fs(temp, std::ios_base::in | std::ios_base::out + std::fstream fs(temp.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); double x = 0; fs << 3.25; @@ -30,9 +30,9 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); { - std::wfstream fs(temp, std::ios_base::in | std::ios_base::out + std::wfstream fs(temp.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); double x = 0; fs << 3.25; @@ -40,5 +40,5 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/fstream.cons/string.pass.cpp b/test/input.output/file.streams/fstreams/fstream.cons/string.pass.cpp index 23795f010..4b0819f8a 100644 --- a/test/input.output/file.streams/fstreams/fstream.cons/string.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.cons/string.pass.cpp @@ -16,13 +16,13 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::fstream fs(std::string(temp), + std::fstream fs(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); double x = 0; @@ -31,9 +31,9 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); { - std::wfstream fs(std::string(temp), + std::wfstream fs(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); double x = 0; @@ -42,5 +42,5 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/fstream.members/close.pass.cpp b/test/input.output/file.streams/fstreams/fstream.members/close.pass.cpp index 94b91806f..0e4bc7177 100644 --- a/test/input.output/file.streams/fstreams/fstream.members/close.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.members/close.pass.cpp @@ -16,27 +16,27 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::fstream fs; assert(!fs.is_open()); - fs.open(temp, std::ios_base::out); + fs.open(temp.c_str(), std::ios_base::out); assert(fs.is_open()); fs.close(); assert(!fs.is_open()); } - remove(temp); + std::remove(temp.c_str()); { std::wfstream fs; assert(!fs.is_open()); - fs.open(temp, std::ios_base::out); + fs.open(temp.c_str(), std::ios_base::out); assert(fs.is_open()); fs.close(); assert(!fs.is_open()); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/fstream.members/open_pointer.pass.cpp b/test/input.output/file.streams/fstreams/fstream.members/open_pointer.pass.cpp index 64c4de9df..231bb82c7 100644 --- a/test/input.output/file.streams/fstreams/fstream.members/open_pointer.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.members/open_pointer.pass.cpp @@ -16,15 +16,15 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::fstream fs; assert(!fs.is_open()); - fs.open(temp, std::ios_base::in | std::ios_base::out + fs.open(temp.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); assert(fs.is_open()); double x = 0; @@ -33,11 +33,11 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); { std::wfstream fs; assert(!fs.is_open()); - fs.open(temp, std::ios_base::in | std::ios_base::out + fs.open(temp.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::trunc); assert(fs.is_open()); double x = 0; @@ -46,5 +46,5 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/fstream.members/open_string.pass.cpp b/test/input.output/file.streams/fstreams/fstream.members/open_string.pass.cpp index a61a4e965..182f12c47 100644 --- a/test/input.output/file.streams/fstreams/fstream.members/open_string.pass.cpp +++ b/test/input.output/file.streams/fstreams/fstream.members/open_string.pass.cpp @@ -16,15 +16,15 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::fstream fs; assert(!fs.is_open()); - fs.open(std::string(temp), std::ios_base::in | std::ios_base::out + fs.open(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); assert(fs.is_open()); double x = 0; @@ -33,11 +33,11 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); { std::wfstream fs; assert(!fs.is_open()); - fs.open(std::string(temp), std::ios_base::in | std::ios_base::out + fs.open(temp, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); assert(fs.is_open()); double x = 0; @@ -46,5 +46,5 @@ int main() fs >> x; assert(x == 3.25); } - std::remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.assign/member_swap.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.assign/member_swap.pass.cpp index 7800c1abe..519b84fb1 100644 --- a/test/input.output/file.streams/fstreams/ofstream.assign/member_swap.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.assign/member_swap.pass.cpp @@ -16,15 +16,15 @@ #include #include +#include "platform_support.h" int main() { - char temp1[L_tmpnam], temp2[L_tmpnam]; - tmpnam(temp1); - tmpnam(temp2); + std::string temp1 = get_temp_file_name(); + std::string temp2 = get_temp_file_name(); { - std::ofstream fs1(temp1); - std::ofstream fs2(temp2); + std::ofstream fs1(temp1.c_str()); + std::ofstream fs2(temp2.c_str()); fs1 << 3.25; fs2 << 4.5; fs1.swap(fs2); @@ -32,26 +32,26 @@ int main() fs2 << ' ' << 4.5; } { - std::ifstream fs(temp1); + std::ifstream fs(temp1.c_str()); double x = 0; fs >> x; assert(x == 3.25); fs >> x; assert(x == 4.5); } - remove(temp1); + std::remove(temp1.c_str()); { - std::ifstream fs(temp2); + std::ifstream fs(temp2.c_str()); double x = 0; fs >> x; assert(x == 4.5); fs >> x; assert(x == 3.25); } - remove(temp2); + std::remove(temp2.c_str()); { - std::wofstream fs1(temp1); - std::wofstream fs2(temp2); + std::wofstream fs1(temp1.c_str()); + std::wofstream fs2(temp2.c_str()); fs1 << 3.25; fs2 << 4.5; fs1.swap(fs2); @@ -59,21 +59,21 @@ int main() fs2 << ' ' << 4.5; } { - std::wifstream fs(temp1); + std::wifstream fs(temp1.c_str()); double x = 0; fs >> x; assert(x == 3.25); fs >> x; assert(x == 4.5); } - remove(temp1); + std::remove(temp1.c_str()); { - std::wifstream fs(temp2); + std::wifstream fs(temp2.c_str()); double x = 0; fs >> x; assert(x == 4.5); fs >> x; assert(x == 3.25); } - remove(temp2); + std::remove(temp2.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.assign/move_assign.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.assign/move_assign.pass.cpp index 7f80cfcc5..0f21eb81d 100644 --- a/test/input.output/file.streams/fstreams/ofstream.assign/move_assign.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.assign/move_assign.pass.cpp @@ -16,37 +16,37 @@ #include #include +#include "platform_support.h" int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::ofstream fso(temp); + std::ofstream fso(temp.c_str()); std::ofstream fs; fs = move(fso); fs << 3.25; } { - std::ifstream fs(temp); + std::ifstream fs(temp.c_str()); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); { - std::wofstream fso(temp); + std::wofstream fso(temp.c_str()); std::wofstream fs; fs = move(fso); fs << 3.25; } { - std::wifstream fs(temp); + std::wifstream fs(temp.c_str()); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/input.output/file.streams/fstreams/ofstream.assign/nonmember_swap.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.assign/nonmember_swap.pass.cpp index 24deafdcf..d58f5f256 100644 --- a/test/input.output/file.streams/fstreams/ofstream.assign/nonmember_swap.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.assign/nonmember_swap.pass.cpp @@ -17,15 +17,15 @@ #include #include +#include "platform_support.h" int main() { - char temp1[L_tmpnam], temp2[L_tmpnam]; - tmpnam(temp1); - tmpnam(temp2); + std::string temp1 = get_temp_file_name(); + std::string temp2 = get_temp_file_name(); { - std::ofstream fs1(temp1); - std::ofstream fs2(temp2); + std::ofstream fs1(temp1.c_str()); + std::ofstream fs2(temp2.c_str()); fs1 << 3.25; fs2 << 4.5; swap(fs1, fs2); @@ -33,26 +33,26 @@ int main() fs2 << ' ' << 4.5; } { - std::ifstream fs(temp1); + std::ifstream fs(temp1.c_str()); double x = 0; fs >> x; assert(x == 3.25); fs >> x; assert(x == 4.5); } - remove(temp1); + std::remove(temp1.c_str()); { - std::ifstream fs(temp2); + std::ifstream fs(temp2.c_str()); double x = 0; fs >> x; assert(x == 4.5); fs >> x; assert(x == 3.25); } - remove(temp2); + std::remove(temp2.c_str()); { - std::wofstream fs1(temp1); - std::wofstream fs2(temp2); + std::wofstream fs1(temp1.c_str()); + std::wofstream fs2(temp2.c_str()); fs1 << 3.25; fs2 << 4.5; swap(fs1, fs2); @@ -60,21 +60,21 @@ int main() fs2 << ' ' << 4.5; } { - std::wifstream fs(temp1); + std::wifstream fs(temp1.c_str()); double x = 0; fs >> x; assert(x == 3.25); fs >> x; assert(x == 4.5); } - remove(temp1); + std::remove(temp1.c_str()); { - std::wifstream fs(temp2); + std::wifstream fs(temp2.c_str()); double x = 0; fs >> x; assert(x == 4.5); fs >> x; assert(x == 3.25); } - remove(temp2); + std::remove(temp2.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.cons/move.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.cons/move.pass.cpp index 93bea0e48..8645358cb 100644 --- a/test/input.output/file.streams/fstreams/ofstream.cons/move.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.cons/move.pass.cpp @@ -16,35 +16,35 @@ #include #include +#include "platform_support.h" int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::ofstream fso(temp); + std::ofstream fso(temp.c_str()); std::ofstream fs = move(fso); fs << 3.25; } { - std::ifstream fs(temp); + std::ifstream fs(temp.c_str()); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); { - std::wofstream fso(temp); + std::wofstream fso(temp.c_str()); std::wofstream fs = move(fso); fs << 3.25; } { - std::wifstream fs(temp); + std::wifstream fs(temp.c_str()); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/test/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp index 7d899e776..bd5832abe 100644 --- a/test/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.cons/pointer.pass.cpp @@ -16,31 +16,31 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::ofstream fs(temp); + std::ofstream fs(temp.c_str()); fs << 3.25; } { - std::ifstream fs(temp); + std::ifstream fs(temp.c_str()); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); { - std::wofstream fs(temp); + std::wofstream fs(temp.c_str()); fs << 3.25; } { - std::wifstream fs(temp); + std::wifstream fs(temp.c_str()); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp index 67dd02aeb..7112b17fb 100644 --- a/test/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.cons/string.pass.cpp @@ -16,31 +16,31 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::ofstream fs((std::string(temp))); + std::ofstream fs(temp); fs << 3.25; } { - std::ifstream fs((std::string(temp))); + std::ifstream fs(temp); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); { - std::wofstream fs((std::string(temp))); + std::wofstream fs(temp); fs << 3.25; } { - std::wifstream fs((std::string(temp))); + std::wifstream fs(temp); double x = 0; fs >> x; assert(x == 3.25); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.members/close.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.members/close.pass.cpp index ad3f3783c..b8c358d8e 100644 --- a/test/input.output/file.streams/fstreams/ofstream.members/close.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.members/close.pass.cpp @@ -16,27 +16,27 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::ofstream fs; assert(!fs.is_open()); - fs.open(temp); + fs.open(temp.c_str()); assert(fs.is_open()); fs.close(); assert(!fs.is_open()); } - remove(temp); + std::remove(temp.c_str()); { std::wofstream fs; assert(!fs.is_open()); - fs.open(temp); + fs.open(temp.c_str()); assert(fs.is_open()); fs.close(); assert(!fs.is_open()); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.members/open_pointer.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.members/open_pointer.pass.cpp index bf8e6a5ca..e5cddc9e1 100644 --- a/test/input.output/file.streams/fstreams/ofstream.members/open_pointer.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.members/open_pointer.pass.cpp @@ -16,43 +16,43 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::ofstream fs; assert(!fs.is_open()); char c = 'a'; fs << c; assert(fs.fail()); - fs.open(temp); + fs.open(temp.c_str()); assert(fs.is_open()); fs << c; } { - std::ifstream fs(temp); + std::ifstream fs(temp.c_str()); char c = 0; fs >> c; assert(c == 'a'); } - remove(temp); + std::remove(temp.c_str()); { std::wofstream fs; assert(!fs.is_open()); wchar_t c = L'a'; fs << c; assert(fs.fail()); - fs.open(temp); + fs.open(temp.c_str()); assert(fs.is_open()); fs << c; } { - std::wifstream fs(temp); + std::wifstream fs(temp.c_str()); wchar_t c = 0; fs >> c; assert(c == L'a'); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.members/open_string.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.members/open_string.pass.cpp index b33114d97..d54aa1824 100644 --- a/test/input.output/file.streams/fstreams/ofstream.members/open_string.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.members/open_string.pass.cpp @@ -16,43 +16,43 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { std::ofstream fs; assert(!fs.is_open()); char c = 'a'; fs << c; assert(fs.fail()); - fs.open(std::string(temp)); + fs.open(temp); assert(fs.is_open()); fs << c; } { - std::ifstream fs(temp); + std::ifstream fs(temp.c_str()); char c = 0; fs >> c; assert(c == 'a'); } - remove(temp); + std::remove(temp.c_str()); { std::wofstream fs; assert(!fs.is_open()); wchar_t c = L'a'; fs << c; assert(fs.fail()); - fs.open(std::string(temp)); + fs.open(temp); assert(fs.is_open()); fs << c; } { - std::wifstream fs(temp); + std::wifstream fs(temp.c_str()); wchar_t c = 0; fs >> c; assert(c == L'a'); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/input.output/file.streams/fstreams/ofstream.members/rdbuf.pass.cpp b/test/input.output/file.streams/fstreams/ofstream.members/rdbuf.pass.cpp index 8860c9ae9..d707e0a32 100644 --- a/test/input.output/file.streams/fstreams/ofstream.members/rdbuf.pass.cpp +++ b/test/input.output/file.streams/fstreams/ofstream.members/rdbuf.pass.cpp @@ -16,21 +16,21 @@ #include #include +#include "platform_support.h" int main() { - char temp[L_tmpnam]; - tmpnam(temp); + std::string temp = get_temp_file_name(); { - std::ofstream fs(temp); + std::ofstream fs(temp.c_str()); std::filebuf* fb = fs.rdbuf(); assert(fb->sputc('r') == 'r'); } - remove(temp); + std::remove(temp.c_str()); { - std::wofstream fs(temp); + std::wofstream fs(temp.c_str()); std::wfilebuf* fb = fs.rdbuf(); assert(fb->sputc(L'r') == L'r'); } - remove(temp); + std::remove(temp.c_str()); } diff --git a/test/support/platform_support.h b/test/support/platform_support.h index 003597501..4633ce047 100644 --- a/test/support/platform_support.h +++ b/test/support/platform_support.h @@ -39,4 +39,25 @@ #define LOCALE_zh_CN_UTF_8 "zh_CN.UTF-8" #endif +#include +#include +#include + +inline +std::string +get_temp_file_name() +{ +#ifdef _WIN32 + char* p = _tempnam( NULL, NULL ); + if (p == nullptr) + abort(); + std::string s(p); + free( p ); +#else + std::string s("temp.XXXX"); + mktemp(&s[0]); +#endif + return s; +} + #endif // PLATFORM_SUPPORT_H