1// { dg-require-fork "" } 2// { dg-require-mkfifo "" } 3 4// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009 5// Free Software Foundation, Inc. 6// 7// This file is part of the GNU ISO C++ Library. This library is free 8// software; you can redistribute it and/or modify it under the 9// terms of the GNU General Public License as published by the 10// Free Software Foundation; either version 3, or (at your option) 11// any later version. 12 13// This library is distributed in the hope that it will be useful, 14// but WITHOUT ANY WARRANTY; without even the implied warranty of 15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16// GNU General Public License for more details. 17 18// You should have received a copy of the GNU General Public License along 19// with this library; see the file COPYING3. If not see 20// <http://www.gnu.org/licenses/>. 21 22// 27.8.1.4 Overridden virtual functions 23 24#include <unistd.h> 25#include <signal.h> 26#include <fcntl.h> 27#include <sys/types.h> 28#include <sys/stat.h> 29#include <fstream> 30#include <cstdlib> 31#include <testsuite_hooks.h> 32 33// libstdc++/9533 34void test_01() 35{ 36 using namespace std; 37 using namespace __gnu_test; 38 bool test __attribute__((unused)) = true; 39 const char* name = "tmp_fifo1"; 40 41 const int count = 10000; 42 43 signal(SIGPIPE, SIG_IGN); 44 unlink(name); 45 46 if (0 != mkfifo(name, S_IRWXU)) 47 { 48 VERIFY( false ); 49 } 50 51 int fval = fork(); 52 if (fval == -1) 53 { 54 unlink(name); 55 VERIFY( false ); 56 } 57 else if (fval == 0) 58 { 59 filebuf ofbuf; 60 ofbuf.open(name, ios_base::in|ios_base::out); 61 VERIFY( ofbuf.is_open() ); 62 sleep(1); 63 64 for (int i = 0; i < count; ++i) 65 ofbuf.sputc(i % 100); 66 67 ofbuf.pubsync(); 68 sleep(1); 69 ofbuf.close(); 70 exit(0); 71 } 72 73 filebuf ifbuf; 74 ifbuf.open(name, ios_base::in); 75 VERIFY( ifbuf.is_open() ); 76 77 for (int j = 0; j < count; ++j) 78 { 79 filebuf::int_type c1 = ifbuf.sbumpc(); 80 VERIFY( c1 == j % 100 ); 81 } 82 83 filebuf::int_type c6 = ifbuf.sbumpc(); 84 VERIFY( c6 == filebuf::traits_type::eof() ); 85 86 sleep(2); 87 ifbuf.close(); 88 89 unlink(name); 90} 91 92int 93main() 94{ 95 test_01(); 96 return 0; 97} 98 99