]> 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-2016 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 bool test __attribute__((unused)) = true;
40 const char* name = "tmp_fifo2";
41
42 signal(SIGPIPE, SIG_IGN);
43
44 unlink(name);
45 mkfifo(name, S_IRWXU);
46
47 std::filebuf fbuf;
48 // The use of ios_base::ate implies an attempt to seek on the file
49 // descriptor. The seek will fail. Thus, at the OS level, this
50 // call to "fbuf.open" will result in a call to "open" (which will
51 // succeed), a call to "lseek" (which will fail), and, finally, a
52 // call to "close" (which will succeed). Thus, after this call, the
53 // file should be closed.
54 std::filebuf* r = fbuf.open(name,
55 std::ios_base::in
56 | std::ios_base::out
57 | std::ios_base::ate);
58 if (!r)
59 VERIFY( !fbuf.is_open() );
60 else
61 VERIFY( fbuf.is_open() );
62 }
63
64 int
65 main()
66 {
67 test_06();
68 return 0;
69 }
70
71