OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_filebuf/] [underflow/] [char/] [10097.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// { dg-require-fork "" }
2
// { dg-require-mkfifo "" }
3
 
4
// 2001-05-21 Benjamin Kosnik  <bkoz@redhat.com>
5
 
6
// Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
7
//
8
// This file is part of the GNU ISO C++ Library.  This library is free
9
// software; you can redistribute it and/or modify it under the
10
// terms of the GNU General Public License as published by the
11
// Free Software Foundation; either version 2, or (at your option)
12
// any later version.
13
 
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
// GNU General Public License for more details.
18
 
19
// You should have received a copy of the GNU General Public License along
20
// with this library; see the file COPYING.  If not, write to the Free
21
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22
// USA.
23
 
24
// 27.8.1.4 Overridden virtual functions
25
 
26
#include <fstream>
27
#include <unistd.h>
28
#include <signal.h>
29
#include <fcntl.h>
30
#include <sys/types.h>
31
#include <sys/stat.h>
32
#include <testsuite_hooks.h>
33
 
34
class UnderBuf : public std::filebuf
35
{
36
public:
37
  int_type
38
  pub_underflow()
39
  { return underflow(); }
40
 
41
  std::streamsize
42
  pub_showmanyc()
43
  { return showmanyc(); }
44
};
45
 
46
// libstdc++/10097
47
// filebuf::underflow drops characters.
48
void test16()
49
{
50
  using namespace std;
51
  using namespace __gnu_test;
52
  bool test __attribute__((unused)) = true;
53
 
54
  const char* name = "tmp_fifo1";
55
 
56
  signal(SIGPIPE, SIG_IGN);
57
  unlink(name);
58
 
59
  if (0 != mkfifo(name, S_IRWXU))
60
    {
61
      VERIFY( false );
62
    }
63
 
64
  semaphore s1;
65
  int fval = fork();
66
  if (fval == -1)
67
    {
68
      unlink(name);
69
      VERIFY( false );
70
    }
71
  else if (fval == 0)
72
    {
73
      filebuf fbout;
74
      fbout.open(name, ios_base::in|ios_base::out);
75
      VERIFY ( fbout.is_open() );
76
      fbout.sputn("0123456789", 10);
77
      fbout.pubsync();
78
      s1.wait ();
79
      fbout.close();
80
      exit(0);
81
    }
82
 
83
  UnderBuf fb;
84
  fb.open(name, ios_base::in);
85
 
86
  fb.sgetc();
87
  streamsize n = fb.pub_showmanyc();
88
 
89
  while (n > 0)
90
    {
91
      --n;
92
 
93
      UnderBuf::int_type c = fb.pub_underflow();
94
      VERIFY( c != UnderBuf::traits_type::eof() );
95
 
96
      fb.sbumpc();
97
    }
98
 
99
  fb.close();
100
  s1.signal ();
101
}
102
 
103
int main()
104
{
105
  test16();
106
  return 0;
107
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.