]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
34f4edf8
MM
1// { dg-require-mkfifo "" }
2
a945c346 3// Copyright (C) 2001-2024 Free Software Foundation, Inc.
23cac885
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
23cac885
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
23cac885
BK
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
36void test_06()
37{
ea1ea21a 38 using namespace __gnu_test;
23cac885
BK
39 const char* name = "tmp_fifo2";
40
41 signal(SIGPIPE, SIG_IGN);
42
43 unlink(name);
34f4edf8 44 mkfifo(name, S_IRWXU);
8f1032c1 45
23cac885 46 std::filebuf fbuf;
5cfa4794
MM
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.
6a734d61
BK
53 std::filebuf* r = fbuf.open(name,
54 std::ios_base::in
55 | std::ios_base::out
56 | std::ios_base::ate);
8fc81078 57 if (!r)
7e4d34fd
LR
58 VERIFY( !fbuf.is_open() );
59 else
60 VERIFY( fbuf.is_open() );
23cac885
BK
61}
62
63int
64main()
65{
66 test_06();
67 return 0;
68}
69
70