| 1 |
// { dg-require-mkfifo "" } |
| 2 |
|
| 3 |
// Copyright (C) 2001-2025 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 |
// C++98 27.8.1.3 filebuf member functions |
| 21 |
|
| 22 |
// various tests for filebuf::open() and filebuf::close() including |
| 23 |
// the non-portable functionality in the libstdc++-v3 IO library |
| 24 |
|
| 25 |
#include <fstream> |
| 26 |
#include <unistd.h> |
| 27 |
#include <signal.h> |
| 28 |
#include <fcntl.h> |
| 29 |
#include <sys/types.h> |
| 30 |
#include <sys/stat.h> |
| 31 |
#include <testsuite_hooks.h> |
| 32 |
|
| 33 |
// libstdc++/9507 |
| 34 |
void test_06() |
| 35 |
{ |
| 36 |
using namespace __gnu_test; |
| 37 |
const char* name = "tmp_fifo2"; |
| 38 |
|
| 39 |
signal(SIGPIPE, SIG_IGN); |
| 40 |
|
| 41 |
unlink(name); |
| 42 |
mkfifo(name, S_IRWXU); |
| 43 |
|
| 44 |
std::filebuf fbuf; |
| 45 |
// The use of ios_base::ate implies an attempt to seek on the file |
| 46 |
// descriptor. The seek will fail. Thus, at the OS level, this |
| 47 |
// call to "fbuf.open" will result in a call to "open" (which will |
| 48 |
// succeed), a call to "lseek" (which will fail), and, finally, a |
| 49 |
// call to "close" (which will succeed). Thus, after this call, the |
| 50 |
// file should be closed. |
| 51 |
std::filebuf* r = fbuf.open(name, |
| 52 |
std::ios_base::in |
| 53 |
| std::ios_base::out |
| 54 |
| std::ios_base::ate); |
| 55 |
if (!r) |
| 56 |
VERIFY( !fbuf.is_open() ); |
| 57 |
else |
| 58 |
VERIFY( fbuf.is_open() ); |
| 59 |
} |
| 60 |
|
| 61 |
int |
| 62 |
main() |
| 63 |
{ |
| 64 |
test_06(); |
| 65 |
return 0; |
| 66 |
} |
| 67 |
|
| 68 |
|