| 1 | // { dg-require-namedlocale "en_US.ISO8859-1" } |
| 2 | // { dg-require-fork "" } |
| 3 | // { dg-require-mkfifo "" } |
| 4 | |
| 5 | // 2004-04-16 Petur Runolfsson <[email protected]> |
| 6 | |
| 7 | // Copyright (C) 2004-2025 Free Software Foundation, Inc. |
| 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 |
| 12 | // Free Software Foundation; either version 3, or (at your option) |
| 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 |
| 21 | // with this library; see the file COPYING3. If not see |
| 22 | // <http://www.gnu.org/licenses/>. |
| 23 | |
| 24 | #include <fstream> |
| 25 | #include <locale> |
| 26 | #include <cstdlib> |
| 27 | #include <unistd.h> |
| 28 | #include <signal.h> |
| 29 | #include <fcntl.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
| 32 | |
| 33 | #include <testsuite_hooks.h> |
| 34 | |
| 35 | // libstdc++/14975 |
| 36 | bool test01() |
| 37 | { |
| 38 | using namespace std; |
| 39 | using namespace __gnu_test; |
| 40 | bool test = true; |
| 41 | |
| 42 | locale loc_us = locale(ISO_8859(1,en_US)); |
| 43 | |
| 44 | const char* name = "tmp_14975-2"; |
| 45 | |
| 46 | signal(SIGPIPE, SIG_IGN); |
| 47 | |
| 48 | unlink(name); |
| 49 | mkfifo(name, S_IRWXU); |
| 50 | semaphore s1; |
| 51 | |
| 52 | int child = fork(); |
| 53 | test &= bool( child != -1 ); |
| 54 | |
| 55 | if (child == 0) |
| 56 | { |
| 57 | { |
| 58 | filebuf fbin; |
| 59 | fbin.open(name, ios_base::in); |
| 60 | } |
| 61 | s1.signal(); |
| 62 | exit(0); |
| 63 | } |
| 64 | |
| 65 | wfilebuf fb; |
| 66 | fb.pubimbue(loc_us); |
| 67 | wfilebuf* ret = fb.open(name, ios_base::out); |
| 68 | test &= bool( ret != 0 ); |
| 69 | test &= bool( fb.is_open() ); |
| 70 | |
| 71 | s1.wait(); |
| 72 | |
| 73 | try |
| 74 | { |
| 75 | fb.sputc(L'a'); |
| 76 | fb.sputc(L'b'); |
| 77 | fb.pubimbue(locale::classic()); |
| 78 | fb.sputc(L'c'); |
| 79 | fb.close(); |
| 80 | } |
| 81 | catch (std::exception&) |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | return test; |
| 86 | } |
| 87 | |
| 88 | int main() |
| 89 | { |
| 90 | return !test01(); |
| 91 | } |