]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc
[multiple changes]
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / imbue / wchar_t / 14975-2.cc
1 // { dg-require-namedlocale "en_US" }
2 // { dg-require-fork "" }
3 // { dg-require-mkfifo "" }
4
5 // 2004-04-16 Petur Runolfsson <peturr02@ru.is>
6
7 // Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010
8 // Free Software Foundation, Inc.
9 //
10 // This file is part of the GNU ISO C++ Library. This library is free
11 // software; you can redistribute it and/or modify it under the
12 // terms of the GNU General Public License as published by the
13 // Free Software Foundation; either version 3, or (at your option)
14 // any later version.
15
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20
21 // You should have received a copy of the GNU General Public License along
22 // with this library; see the file COPYING3. If not see
23 // <http://www.gnu.org/licenses/>.
24
25 #include <fstream>
26 #include <locale>
27 #include <cstdlib>
28 #include <unistd.h>
29 #include <signal.h>
30 #include <fcntl.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33
34 // No asserts, avoid leaking the semaphore if a VERIFY fails.
35 #undef _GLIBCXX_ASSERT
36
37 #include <testsuite_hooks.h>
38
39 // libstdc++/14975
40 bool test01()
41 {
42 using namespace std;
43 using namespace __gnu_test;
44 bool test __attribute__((unused)) = true;
45
46 locale loc_us = locale("en_US");
47
48 const char* name = "tmp_14975-2";
49
50 signal(SIGPIPE, SIG_IGN);
51
52 unlink(name);
53 mkfifo(name, S_IRWXU);
54 semaphore s1;
55
56 int child = fork();
57 VERIFY( child != -1 );
58
59 if (child == 0)
60 {
61 {
62 filebuf fbin;
63 fbin.open(name, ios_base::in);
64 }
65 s1.signal();
66 exit(0);
67 }
68
69 wfilebuf fb;
70 fb.pubimbue(loc_us);
71 wfilebuf* ret = fb.open(name, ios_base::out);
72 VERIFY( ret != 0 );
73 VERIFY( fb.is_open() );
74
75 s1.wait();
76
77 try
78 {
79 fb.sputc(L'a');
80 fb.sputc(L'b');
81 fb.pubimbue(locale::classic());
82 fb.sputc(L'c');
83 fb.close();
84 }
85 catch (std::exception&)
86 {
87 }
88
89 return test;
90 }
91
92 int main()
93 {
94 return !test01();
95 }