X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=libstdc%2B%2B-v3%2Finclude%2Fext%2Fstdio_filebuf.h;fp=libstdc%2B%2B-v3%2Finclude%2Fext%2Fstdio_filebuf.h;h=6efe4ea12f14e6af8c1c5f0f84795594545f0a79;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=59ab41a03e559136ca10ebb42dc110e4e51f0ff4;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/libstdc++-v3/include/ext/stdio_filebuf.h b/libstdc++-v3/include/ext/stdio_filebuf.h index 59ab41a0..6efe4ea1 100644 --- a/libstdc++-v3/include/ext/stdio_filebuf.h +++ b/libstdc++-v3/include/ext/stdio_filebuf.h @@ -1,11 +1,11 @@ // File descriptor layer for filebuf -*- C++ -*- -// Copyright (C) 2002 Free Software Foundation, Inc. +// Copyright (C) 2002, 2003, 2004, 2005, 2009 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 // terms of the GNU General Public License as published by the -// Free Software Foundation; either version 2, or (at your option) +// Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, @@ -13,34 +13,29 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// You should have received a copy of the GNU General Public License along -// with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, -// USA. +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. -// As a special exception, you may use this file as part of a free software -// library without restriction. Specifically, if other files instantiate -// templates or use macros or inline functions from this file, or you compile -// this file and link it with other files to produce an executable, this -// file does not by itself cause the resulting executable to be covered by -// the GNU General Public License. This exception does not however -// invalidate any other reasons why the executable file might be covered by -// the GNU General Public License. +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . /** @file ext/stdio_filebuf.h * This file is a GNU extension to the Standard C++ Library. */ -#ifndef _EXT_STDIO_FILEBUF -#define _EXT_STDIO_FILEBUF +#ifndef _STDIO_FILEBUF_H +#define _STDIO_FILEBUF_H 1 #pragma GCC system_header + #include -namespace __gnu_cxx -{ +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + /** - * @class stdio_filebuf ext/stdio_filebuf.h * @brief Provides a layer of compatibility for C/POSIX. * * This GNU extension provides extensions for working with standard C @@ -53,46 +48,47 @@ namespace __gnu_cxx { public: // Types: - typedef _CharT char_type; - typedef _Traits traits_type; - typedef typename traits_type::int_type int_type; - typedef typename traits_type::pos_type pos_type; - typedef typename traits_type::off_type off_type; - - protected: - // Stack-based buffer for unbuffered input. - char_type _M_unbuf[4]; - + typedef _CharT char_type; + typedef _Traits traits_type; + typedef typename traits_type::int_type int_type; + typedef typename traits_type::pos_type pos_type; + typedef typename traits_type::off_type off_type; + typedef std::size_t size_t; + public: + /** + * deferred initialization + */ + stdio_filebuf() : std::basic_filebuf<_CharT, _Traits>() {} + /** * @param fd An open file descriptor. * @param mode Same meaning as in a standard filebuf. - * @param del Whether to close the file on destruction. - * @param size Optimal or preferred size of internal buffer, in bytes. + * @param size Optimal or preferred size of internal buffer, in chars. * * This constructor associates a file stream buffer with an open - * POSIX file descriptor. Iff @a del is true, then the associated - * file will be closed when the stdio_filebuf is closed/destroyed. + * POSIX file descriptor. The file descriptor will be automatically + * closed when the stdio_filebuf is closed/destroyed. */ - stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, - int_type __size); + stdio_filebuf(int __fd, std::ios_base::openmode __mode, + size_t __size = static_cast(BUFSIZ)); /** * @param f An open @c FILE*. * @param mode Same meaning as in a standard filebuf. - * @param size Optimal or preferred size of internal buffer, in bytes. + * @param size Optimal or preferred size of internal buffer, in chars. * Defaults to system's @c BUFSIZ. * * This constructor associates a file stream buffer with an open * C @c FILE*. The @c FILE* will not be automatically closed when the * stdio_filebuf is closed/destroyed. */ - stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, - int_type __size = static_cast(BUFSIZ)); + stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, + size_t __size = static_cast(BUFSIZ)); /** - * Possibly closes the external data stream, in the case of the file - * descriptor constructor and @c del @c == @c true. + * Closes the external data stream if the file descriptor constructor + * was used. */ virtual ~stdio_filebuf(); @@ -106,8 +102,17 @@ namespace __gnu_cxx * descriptor, so be careful. */ int - fd() - { return _M_file.fd(); } + fd() { return this->_M_file.fd(); } + + /** + * @return The underlying FILE*. + * + * This function can be used to access the underlying "C" file pointer. + * Note that there is no way for the library to track what you do + * with the file, so be careful. + */ + std::__c_file* + file() { return this->_M_file.file(); } }; template @@ -116,53 +121,37 @@ namespace __gnu_cxx template stdio_filebuf<_CharT, _Traits>:: - stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, - int_type __size) + stdio_filebuf(int __fd, std::ios_base::openmode __mode, size_t __size) { - _M_file.sys_open(__fd, __mode, __del); + this->_M_file.sys_open(__fd, __mode); if (this->is_open()) { - _M_mode = __mode; - if (__size > 0 && __size < 4) - { - // Specify unbuffered. - _M_buf = _M_unbuf; - _M_buf_size = __size; - _M_buf_size_opt = 0; - } - else - { - _M_buf_size_opt = __size; - _M_allocate_internal_buffer(); - } - _M_set_indeterminate(); + this->_M_mode = __mode; + this->_M_buf_size = __size; + this->_M_allocate_internal_buffer(); + this->_M_reading = false; + this->_M_writing = false; + this->_M_set_buffer(-1); } } template stdio_filebuf<_CharT, _Traits>:: - stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, - int_type __size) + stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, + size_t __size) { - _M_file.sys_open(__f, __mode); + this->_M_file.sys_open(__f, __mode); if (this->is_open()) { - _M_mode = __mode; - if (__size > 0 && __size < 4) - { - // Specify unbuffered. - _M_buf = _M_unbuf; - _M_buf_size = __size; - _M_buf_size_opt = 0; - } - else - { - _M_buf_size_opt = __size; - _M_allocate_internal_buffer(); - } - _M_set_indeterminate(); + this->_M_mode = __mode; + this->_M_buf_size = __size; + this->_M_allocate_internal_buffer(); + this->_M_reading = false; + this->_M_writing = false; + this->_M_set_buffer(-1); } } -} // namespace __gnu_cxx -#endif /* _EXT_STDIO_FILEBUF */ +_GLIBCXX_END_NAMESPACE + +#endif