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