Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc

raw
1 // { dg-require-fork "" }
2 // { dg-require-mkfifo "" }
3
4 // Copyright (C) 2001-2025 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // C++98 27.8.1.3 filebuf member functions
22
23 // various tests for filebuf::open() and filebuf::close() including
24 // the non-portable functionality in the libstdc++-v3 IO library
25
26 #include <fstream>
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 #include <testsuite_hooks.h>
35
36 // libstdc++/9964
37 bool test_07()
38 {
39 using namespace std;
40 using namespace __gnu_test;
41 bool test = true;
42 semaphore s1, s2;
43
44 const char* name = "tmp_fifo3";
45
46 signal(SIGPIPE, SIG_IGN);
47
48 unlink(name);
49 mkfifo(name, S_IRWXU);
50
51 int child = fork();
52 test &= bool( child != -1 );
53
54 if (child == 0)
55 {
56 filebuf fbin;
57 fbin.open(name, ios_base::in);
58 s1.wait();
59 fbin.close();
60 s2.signal();
61 exit(0);
62 }
63
64 filebuf fb;
65 filebuf* ret = fb.open(name, ios_base::in | ios_base::out);
66 test &= bool( ret != 0 );
67 test &= bool( fb.is_open() );
68 s1.signal();
69 s2.wait();
70 fb.sputc('a');
71
72 ret = fb.close();
73 test &= bool( ret != 0 );
74 test &= bool( !fb.is_open() );
75
76 return test;
77 }
78
79 int
80 main()
81 {
82 return !test_07();
83 }