]>
Commit | Line | Data |
---|---|---|
23cac885 BK |
1 | // 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> |
2 | ||
3 | // Copyright (C) 2001, 2002, 2003 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 2, 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 COPYING. If not, write to the Free | |
18 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | ||
21 | // 27.8.1.4 Overridden virtual functions | |
22 | ||
8b87d3fa DB |
23 | // XXX cygwin does not support mkfifo |
24 | // { dg-do run { xfail *-*-cygwin* } } | |
25 | ||
23cac885 BK |
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; | |
11f10e6b | 51 | bool test __attribute__((unused)) = true; |
23cac885 BK |
52 | |
53 | const char* name = "tmp_fifo1"; | |
54 | ||
55 | signal(SIGPIPE, SIG_IGN); | |
56 | unlink(name); | |
57 | ||
58 | if (0 != mkfifo(name, S_IRWXU)) | |
59 | { | |
60 | VERIFY( false ); | |
61 | } | |
62 | ||
63 | int fval = fork(); | |
64 | if (fval == -1) | |
65 | { | |
66 | unlink(name); | |
67 | VERIFY( false ); | |
68 | } | |
69 | else if (fval == 0) | |
70 | { | |
71 | filebuf fbout; | |
72 | fbout.open(name, ios_base::out); | |
73 | fbout.sputn("0123456789", 10); | |
74 | fbout.pubsync(); | |
75 | sleep(2); | |
76 | fbout.close(); | |
77 | exit(0); | |
78 | } | |
79 | ||
80 | UnderBuf fb; | |
81 | fb.open(name, ios_base::in); | |
82 | sleep(1); | |
83 | ||
84 | fb.sgetc(); | |
85 | streamsize n = fb.pub_showmanyc(); | |
86 | ||
87 | while (n > 0) | |
88 | { | |
89 | --n; | |
90 | ||
91 | UnderBuf::int_type c = fb.pub_underflow(); | |
92 | VERIFY( c != UnderBuf::traits_type::eof() ); | |
93 | ||
94 | fb.sbumpc(); | |
95 | } | |
96 | ||
97 | fb.close(); | |
98 | } | |
99 | ||
11f10e6b | 100 | int main() |
23cac885 BK |
101 | { |
102 | test16(); | |
103 | return 0; | |
104 | } |