*** 9964.cc.orig 2004-04-20 14:57:34.000000000 +0000 --- 9964.cc 2004-04-26 20:30:50.000000000 +0000 *************** *** 1,4 **** ! // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the --- 1,4 ---- ! // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the *************** *** 17,29 **** // USA. // 27.8.1.3 filebuf member functions - // @require@ %-*.tst %-*.txt - // @diff@ %-*.tst %-*.txt - - // various tests for filebuf::open() and filebuf::close() including - // the non-portable functionality in the libstdc++-v3 IO library #include #include #include #include --- 17,25 ---- // USA. // 27.8.1.3 filebuf member functions #include + #include #include #include #include *************** *** 32,37 **** --- 28,35 ---- #include // libstdc++/9964 + // Check that if basic_filebuf::close() fails (that is, returns NULL), + // the file still gets closed. void test_07() { using namespace std; *************** void test_07() *** 45,55 **** unlink(name); try_mkfifo(name, S_IRWXU); ! int child = fork(); VERIFY( child != -1 ); if (child == 0) { filebuf fbin; fbin.open(name, ios_base::in); sleep(2); --- 43,56 ---- unlink(name); try_mkfifo(name, S_IRWXU); ! pid_t child = fork(); VERIFY( child != -1 ); if (child == 0) { + // Avoid blocking too long in open + alarm(10); + filebuf fbin; fbin.open(name, ios_base::in); sleep(2); *************** void test_07() *** 57,73 **** exit(0); } - filebuf fb; sleep(1); ! filebuf* ret = fb.open(name, ios_base::in | ios_base::out); ! VERIFY( ret != NULL ); VERIFY( fb.is_open() ); sleep(3); fb.sputc('a'); ! ret = fb.close(); ! VERIFY( ret != NULL ); VERIFY( !fb.is_open() ); } --- 58,84 ---- exit(0); } sleep(1); ! ! // Use ::open + stdio_filebuf to precisely control the flags passed to ! // open. basic_filebuf::open(..., ios_base::out) calls ::open with ! // flags O_WRONLY | O_CREAT | O_TRUNC, which does not work for opening ! // fifos on some systems. ! int fd = open(name, O_WRONLY); ! VERIFY( fd != -1 ); ! ! __gnu_cxx::stdio_filebuf fb(fd, ios_base::out); VERIFY( fb.is_open() ); sleep(3); fb.sputc('a'); ! // Close should fail when it tries to flush the buffer, since the other ! // end of the fifo should be closed by now. ! filebuf* ret = fb.close(); ! // Make sure it failed. ! VERIFY( ret == NULL ); ! // Check that file really was closed. VERIFY( !fb.is_open() ); }