From: Benjamin Kosnik Date: Thu, 5 Feb 2004 20:24:48 +0000 (+0000) Subject: basic_file_stdio.cc (__gnu_internal::fopen_mode): New function. X-Git-Tag: releases/gcc-3.3.3~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23346917d780d65a155f1b88f427f943177c37aa;p=thirdparty%2Fgcc.git basic_file_stdio.cc (__gnu_internal::fopen_mode): New function. 2004-02-04 Benjamin Kosnik Zack Weinberg * config/io/basic_file_stdio.cc (__gnu_internal::fopen_mode): New function. (__basic_file::sys_open, __basic_file::open): Use it. (__basic_file::_M_open_mode): Use it. Mark deprecated. * testsuite/27_io/filebuf_members.cc (test_06, test_07): Correct flags to filebuf::open calls. From-SVN: r77340 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index fed0a597f1d1..aaeb6e141936 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,16 @@ +2004-02-04 Benjamin Kosnik + Zack Weinberg + + * config/io/basic_file_stdio.cc (__gnu_internal::fopen_mode): + New function. + (__basic_file::sys_open, __basic_file::open): Use it. + (__basic_file::_M_open_mode): Use it. Mark deprecated. + + * testsuite/27_io/filebuf_members.cc (test_06, test_07): + Correct flags to filebuf::open calls. + 2004-01-29 Paolo Carlini - + PR libstdc++/12657 * include/bits/basic_ios.tcc (copyfmt(const basic_ios&)): Implement resolution of DR 292 (WP). @@ -69,7 +80,7 @@ PR libstdc++/12540 * config/locale/gnu/monetary_members.cc: Don't leak memory on exception. - + 2004-01-26 Andreas Schwab * config/locale/gnu/monetary_members.cc: Restore locale before @@ -117,7 +128,7 @@ 2004-01-07 Paolo Carlini Petur Runolfsson - + PR libstdc++/13007 * include/bits/fstream.tcc (imbue): Don't touch the stored locale. @@ -133,8 +144,8 @@ LD_LIBRARY_PATH to both. Based on libjava.exp. 2003-12-10 Benjamin Kosnik - Alexandre Oliva - + Alexandre Oliva + PR libstdc++/11612 * testsuite/Makefile.am (GLIBCXX_DIR): New. (GLIBGCC_DIR): New. @@ -169,14 +180,14 @@ * include/bits/basic_ios.tcc: Tweak. * include/bits/fstream.tcc: Tweak. * include/bits/istream.tcc: Use _M_setstate for common exception - handling. Move setstate calls after catch. + handling. Move setstate calls after catch. (basic_istream::tellg): Check for exceptions thrown by streambuf virtual functions. (basic_istream::seekg): Same. * include/bits/ostream.tcc: Same, but for ostream. (basic_ostream::flush): Check for exceptions thrown by streambuf virtual functions. - (basic_istream::tellp): Same. + (basic_istream::tellp): Same. (basic_istream::seekp): Same. * include/bits/locale_facets.tcc: Tweak. * include/bits/streambuf.tcc: Tweak. @@ -231,7 +242,7 @@ PR libstdc++/12451 * libsupc++/cxxabi.h: Move forward declaration of __class_type_info. - + 2003-10-01 Rainer Orth * configure.target: Handle Solaris 2.5 micro releases explicitly. @@ -246,7 +257,7 @@ returns eof. 2003-09-30 Nathan Myers - Paolo Carlini + Paolo Carlini PR libstdc++/11400 * include/bits/stl_algo.h (search_n): diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc index 5393a1487a60..476e11a5d9fd 100644 --- a/libstdc++-v3/config/io/basic_file_stdio.cc +++ b/libstdc++-v3/config/io/basic_file_stdio.cc @@ -1,6 +1,6 @@ // Wrapper of C-language FILE struct -*- C++ -*- -// Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. +// Copyright (C) 2000, 2001, 2002, 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 @@ -58,6 +58,43 @@ # endif #endif +namespace __gnu_internal +{ + // Map ios_base::openmode flags to a string for use in fopen(). + // Table of valid combinations as given in [lib.filebuf.members]/2. + static const char* + fopen_mode(std::ios_base::openmode mode) + { + enum + { + in = std::ios_base::in, + out = std::ios_base::out, + trunc = std::ios_base::trunc, + app = std::ios_base::app, + binary = std::ios_base::binary + }; + + switch (mode & (in|out|trunc|app|binary)) + { + case ( out ): return "w"; + case ( out |app ): return "a"; + case ( out|trunc ): return "w"; + case (in ): return "r"; + case (in|out ): return "r+"; + case (in|out|trunc ): return "w+"; + + case ( out |binary): return "wb"; + case ( out |app|binary): return "ab"; + case ( out|trunc |binary): return "wb"; + case (in |binary): return "rb"; + case (in|out |binary): return "r+b"; + case (in|out|trunc |binary): return "w+b"; + + default: return 0; // invalid + } + } +} // namespace __gnu_internal + namespace std { // Definitions for __basic_file. @@ -66,52 +103,16 @@ namespace std __basic_file::~__basic_file() { this->close(); } - - void - __basic_file::_M_open_mode(ios_base::openmode __mode, int& __p_mode, - int&, char* __c_mode) - { - bool __testb = __mode & ios_base::binary; - bool __testi = __mode & ios_base::in; - bool __testo = __mode & ios_base::out; - bool __testt = __mode & ios_base::trunc; - bool __testa = __mode & ios_base::app; - - // Set __c_mode for use in fopen. - // Set __p_mode for use in open. - if (!__testi && __testo && !__testt && !__testa) - { - strcpy(__c_mode, "w"); - __p_mode = (O_WRONLY | O_CREAT); - } - if (!__testi && __testo && !__testt && __testa) - { - strcpy(__c_mode, "a"); - __p_mode |= O_WRONLY | O_CREAT | O_APPEND; - } - if (!__testi && __testo && __testt && !__testa) - { - strcpy(__c_mode, "w"); - __p_mode |= O_WRONLY | O_CREAT | O_TRUNC; - } - if (__testi && !__testo && !__testt && !__testa) - { - strcpy(__c_mode, "r"); - __p_mode |= O_RDONLY; - } - if (__testi && __testo && !__testt && !__testa) - { - strcpy(__c_mode, "r+"); - __p_mode |= O_RDWR | O_CREAT; - } - if (__testi && __testo && __testt && !__testa) - { - strcpy(__c_mode, "w+"); - __p_mode |= O_RDWR | O_CREAT | O_TRUNC; - } - if (__testb) - strcat(__c_mode, "b"); + // Preserved for binary compatibility only. + // Do not use. Gone in 3.4. + void + __basic_file::_M_open_mode(ios_base::openmode __mode, int&, int&, + char* __c_mode) + { + const char* r = __gnu_internal::fopen_mode(__mode); + if (r) + strcpy(__c_mode, r); } __basic_file* @@ -132,12 +133,9 @@ namespace std bool __del) { __basic_file* __ret = NULL; - int __p_mode = 0; - int __rw_mode = 0; - char __c_mode[4]; - - _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode); - if (!this->is_open() && (_M_cfile = fdopen(__fd, __c_mode))) + const char* __c_mode = __gnu_internal::fopen_mode(__mode); + if (__c_mode && !this->is_open() + && (_M_cfile = fdopen(__fd, __c_mode))) { // Iff __del is true, then close will fclose the fd. _M_cfile_created = __del; @@ -163,13 +161,8 @@ namespace std int /*__prot*/) { __basic_file* __ret = NULL; - int __p_mode = 0; - int __rw_mode = 0; - char __c_mode[4]; - - _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode); - - if (!this->is_open()) + const char* __c_mode = __gnu_internal::fopen_mode(__mode); + if (__c_mode && !this->is_open()) { if ((_M_cfile = fopen(__name, __c_mode))) { diff --git a/libstdc++-v3/testsuite/27_io/filebuf_members.cc b/libstdc++-v3/testsuite/27_io/filebuf_members.cc index c873b366ade3..a504331a62aa 100644 --- a/libstdc++-v3/testsuite/27_io/filebuf_members.cc +++ b/libstdc++-v3/testsuite/27_io/filebuf_members.cc @@ -217,7 +217,10 @@ void test_06() } std::filebuf fbuf; - std::filebuf* r = fbuf.open(name, std::ios_base::out | std::ios_base::ate); + std::filebuf* r = fbuf.open(name, + std::ios_base::in + | std::ios_base::out + | std::ios_base::ate); VERIFY( !fbuf.is_open() ); VERIFY( r == NULL ); } @@ -249,7 +252,7 @@ void test_07() filebuf fb; sleep(1); - filebuf* ret = fb.open(name, ios_base::out | ios_base::trunc); + filebuf* ret = fb.open(name, ios_base::in | ios_base::out); VERIFY( ret != NULL ); VERIFY( fb.is_open() ); @@ -257,7 +260,7 @@ void test_07() fb.sputc('a'); ret = fb.close(); - VERIFY( ret == NULL ); + VERIFY( ret != NULL ); VERIFY( !fb.is_open() ); }