]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / open / char / 9507.cc
1 // { dg-require-mkfifo "" }
2
3 // Copyright (C) 2001-2019 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 27.8.1.3 filebuf member functions
21 // @require@ %-*.tst %-*.txt
22 // @diff@ %-*.tst %-*.txt
23
24 // various tests for filebuf::open() and filebuf::close() including
25 // the non-portable functionality in the libstdc++-v3 IO library
26
27 #include <fstream>
28 #include <unistd.h>
29 #include <signal.h>
30 #include <fcntl.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <testsuite_hooks.h>
34
35 // libstdc++/9507
36 void test_06()
37 {
38 using namespace __gnu_test;
39 const char* name = "tmp_fifo2";
40
41 signal(SIGPIPE, SIG_IGN);
42
43 unlink(name);
44 mkfifo(name, S_IRWXU);
45
46 std::filebuf fbuf;
47 // The use of ios_base::ate implies an attempt to seek on the file
48 // descriptor. The seek will fail. Thus, at the OS level, this
49 // call to "fbuf.open" will result in a call to "open" (which will
50 // succeed), a call to "lseek" (which will fail), and, finally, a
51 // call to "close" (which will succeed). Thus, after this call, the
52 // file should be closed.
53 std::filebuf* r = fbuf.open(name,
54 std::ios_base::in
55 | std::ios_base::out
56 | std::ios_base::ate);
57 if (!r)
58 VERIFY( !fbuf.is_open() );
59 else
60 VERIFY( fbuf.is_open() );
61 }
62
63 int
64 main()
65 {
66 test_06();
67 return 0;
68 }
69
70