1// { dg-require-fork "" } 2// { dg-require-mkfifo "" } 3 4// Copyright (C) 2001, 2002, 2003, 2005 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 2, 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 COPYING. If not, write to the Free 19// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20// USA. 21 22// 27.8.1.3 filebuf member functions 23// @require@ %-*.tst %-*.txt 24// @diff@ %-*.tst %-*.txt 25 26// various tests for filebuf::open() and filebuf::close() including 27// the non-portable functionality in the libstdc++-v3 IO library 28 29#include <fstream> 30#include <unistd.h> 31#include <signal.h> 32#include <fcntl.h> 33#include <sys/types.h> 34#include <sys/stat.h> 35#include <testsuite_hooks.h> 36 37// libstdc++/9964 38void test_07() 39{ 40 using namespace std; 41 using namespace __gnu_test; 42 bool test __attribute__((unused)) = true; 43 semaphore s1, s2; 44 45 const char* name = "tmp_fifo3"; 46 47 signal(SIGPIPE, SIG_IGN); 48 49 unlink(name); 50 mkfifo(name, S_IRWXU); 51 52 int child = fork(); 53 VERIFY( child != -1 ); 54 55 if (child == 0) 56 { 57 filebuf fbin; 58 fbin.open(name, ios_base::in); 59 s1.wait (); 60 fbin.close(); 61 s2.signal (); 62 exit(0); 63 } 64 65 filebuf fb; 66 filebuf* ret = fb.open(name, ios_base::in | ios_base::out); 67 VERIFY( ret != NULL ); 68 VERIFY( fb.is_open() ); 69 s1.signal (); 70 s2.wait (); 71 fb.sputc('a'); 72 73 ret = fb.close(); 74 VERIFY( ret != NULL ); 75 VERIFY( !fb.is_open() ); 76} 77 78int 79main() 80{ 81 test_07(); 82 return 0; 83} 84