2001-02-28 04:20:36 +01:00
|
|
|
// Wrapper of C-language FILE struct -*- C++ -*-
|
|
|
|
|
2007-11-08 17:22:21 +01:00
|
|
|
// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2007
|
2006-09-12 19:48:45 +02:00
|
|
|
// Free Software Foundation, Inc.
|
2001-02-28 04:20:36 +01:00
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
// any later version.
|
|
|
|
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// 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
|
2005-08-17 04:28:44 +02:00
|
|
|
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
2001-02-28 04:20:36 +01:00
|
|
|
// USA.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
//
|
|
|
|
// ISO C++ 14882: 27.8 File-based streams
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <bits/basic_file.h>
|
2002-11-12 00:18:05 +01:00
|
|
|
#include <fcntl.h>
|
re PR libstdc++/7744 (streambuf::in_avail() always returns 0 (zero) for cin input stream)
2003-03-09 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org>
PR libstdc++/7744
* config/io/basic_file_stdio.h (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): Add a boolean parameter __stdio.
* config/io/basic_file_stdio.cc (__basic_file<>::xsgetn, xsputn,
seekoff, seekpos): If __stdio == true, use fread (fwrite, fseek/ftell,
fseek/ftell, respectively), otherwise read (write, lseek, lseek,
respectively).
* include/bits/fstream.tcc (basic_filebuf<>::_M_convert_to_external,
_M_really_overflow, seekoff): Use the boolean parameter in the calls.
* include/std/std_fstream.h (sync): Likewise.
* src/fstream.cc (basic_filebuf<>::_M_underflow_common): Likewise.
* src/ios.cc (ios_base::Init::_S_ios_create(bool)): Revert libstdc++/8399
commit involving isatty(0).
* acinclude.m4 (GLIBCPP_CHECK_UNISTD_DECL_AND_LINKAGE_1): Remove.
(GLIBCPP_CHECK_UNISTD_SUPPORT): Remove
* configure.in: Remove call.
* aclocal.m4: Regenerate.
* config.h.in: Regenerate.
* configure: Regenerate.
* testsuite/27_io/narrow_stream_objects.cc (test11): Add.
Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r64051
2003-03-09 23:31:45 +01:00
|
|
|
#include <errno.h>
|
2001-02-28 04:20:36 +01:00
|
|
|
|
2003-09-25 22:30:20 +02:00
|
|
|
#ifdef _GLIBCXX_HAVE_POLL
|
|
|
|
#include <poll.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Pick up ioctl on Solaris 2.8
|
|
|
|
#ifdef _GLIBCXX_HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Pick up FIONREAD on Solaris 2
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifdef _GLIBCXX_HAVE_SYS_IOCTL_H
|
2003-09-25 22:30:20 +02:00
|
|
|
#define BSD_COMP
|
2003-03-28 19:28:47 +01:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Pick up FIONREAD on Solaris 2.5.
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifdef _GLIBCXX_HAVE_SYS_FILIO_H
|
2003-03-28 19:28:47 +01:00
|
|
|
#include <sys/filio.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-14 20:23:12 +02:00
|
|
|
#ifdef _GLIBCXX_HAVE_SYS_UIO_H
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#if defined(_GLIBCXX_HAVE_S_ISREG) || defined(_GLIBCXX_HAVE_S_IFREG)
|
2003-03-28 19:28:47 +01:00
|
|
|
# include <sys/stat.h>
|
2003-07-05 06:05:45 +02:00
|
|
|
# ifdef _GLIBCXX_HAVE_S_ISREG
|
|
|
|
# define _GLIBCXX_ISREG(x) S_ISREG(x)
|
2003-03-28 19:28:47 +01:00
|
|
|
# else
|
2003-07-05 06:05:45 +02:00
|
|
|
# define _GLIBCXX_ISREG(x) (((x) & S_IFMT) == S_IFREG)
|
2003-03-28 19:28:47 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2004-09-21 11:06:08 +02:00
|
|
|
#include <limits> // For <off_t>::max() and min() and <streamsize>::max()
|
2003-10-22 17:51:55 +02:00
|
|
|
|
2006-09-12 19:48:45 +02:00
|
|
|
namespace
|
2004-02-05 06:24:18 +01:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
};
|
2007-11-08 17:22:21 +01:00
|
|
|
|
|
|
|
// _GLIBCXX_RESOLVE_LIB_DEFECTS
|
|
|
|
// 596. 27.8.1.3 Table 112 omits "a+" and "a+b" modes.
|
2004-02-05 06:24:18 +01:00
|
|
|
switch (mode & (in|out|trunc|app|binary))
|
|
|
|
{
|
2007-11-08 17:22:21 +01:00
|
|
|
case ( out ): return "w";
|
|
|
|
case ( out |app ): return "a";
|
|
|
|
case ( app ): return "a";
|
|
|
|
case ( out|trunc ): return "w";
|
|
|
|
case (in ): return "r";
|
|
|
|
case (in|out ): return "r+";
|
|
|
|
case (in|out|trunc ): return "w+";
|
|
|
|
case (in|out |app ): return "a+";
|
|
|
|
case (in |app ): return "a+";
|
|
|
|
|
|
|
|
case ( out |binary): return "wb";
|
|
|
|
case ( out |app|binary): return "ab";
|
|
|
|
case ( app|binary): return "ab";
|
|
|
|
case ( out|trunc |binary): return "wb";
|
|
|
|
case (in |binary): return "rb";
|
2004-02-05 06:24:18 +01:00
|
|
|
case (in|out |binary): return "r+b";
|
|
|
|
case (in|out|trunc |binary): return "w+b";
|
2006-10-01 10:27:49 +02:00
|
|
|
case (in|out |app|binary): return "a+b";
|
2007-11-08 17:22:21 +01:00
|
|
|
case (in |app|binary): return "a+b";
|
|
|
|
|
2004-02-05 06:24:18 +01:00
|
|
|
default: return 0; // invalid
|
|
|
|
}
|
|
|
|
}
|
2004-02-12 19:24:07 +01:00
|
|
|
|
|
|
|
// Wrapper handling partial write.
|
|
|
|
static std::streamsize
|
|
|
|
xwrite(int __fd, const char* __s, std::streamsize __n)
|
|
|
|
{
|
|
|
|
std::streamsize __nleft = __n;
|
2004-02-18 09:36:27 +01:00
|
|
|
|
|
|
|
for (;;)
|
2004-02-12 19:24:07 +01:00
|
|
|
{
|
|
|
|
const std::streamsize __ret = write(__fd, __s, __nleft);
|
|
|
|
if (__ret == -1L && errno == EINTR)
|
|
|
|
continue;
|
2004-02-18 09:36:27 +01:00
|
|
|
if (__ret == -1L)
|
2004-02-12 19:24:07 +01:00
|
|
|
break;
|
2004-02-18 09:36:27 +01:00
|
|
|
|
2004-02-12 19:24:07 +01:00
|
|
|
__nleft -= __ret;
|
2004-02-18 09:36:27 +01:00
|
|
|
if (__nleft == 0)
|
|
|
|
break;
|
|
|
|
|
2004-02-12 19:24:07 +01:00
|
|
|
__s += __ret;
|
|
|
|
}
|
2004-02-18 09:36:27 +01:00
|
|
|
|
2004-02-12 19:24:07 +01:00
|
|
|
return __n - __nleft;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _GLIBCXX_HAVE_WRITEV
|
|
|
|
// Wrapper handling partial writev.
|
|
|
|
static std::streamsize
|
|
|
|
xwritev(int __fd, const char* __s1, std::streamsize __n1,
|
|
|
|
const char* __s2, std::streamsize __n2)
|
|
|
|
{
|
2004-02-18 09:36:27 +01:00
|
|
|
std::streamsize __nleft = __n1 + __n2;
|
|
|
|
std::streamsize __n1_left = __n1;
|
2004-02-12 19:24:07 +01:00
|
|
|
|
|
|
|
struct iovec __iov[2];
|
|
|
|
__iov[1].iov_base = const_cast<char*>(__s2);
|
|
|
|
__iov[1].iov_len = __n2;
|
|
|
|
|
2004-02-18 09:36:27 +01:00
|
|
|
for (;;)
|
2004-02-12 19:24:07 +01:00
|
|
|
{
|
2004-02-18 09:36:27 +01:00
|
|
|
__iov[0].iov_base = const_cast<char*>(__s1);
|
|
|
|
__iov[0].iov_len = __n1_left;
|
|
|
|
|
|
|
|
const std::streamsize __ret = writev(__fd, __iov, 2);
|
|
|
|
if (__ret == -1L && errno == EINTR)
|
|
|
|
continue;
|
|
|
|
if (__ret == -1L)
|
|
|
|
break;
|
|
|
|
|
|
|
|
__nleft -= __ret;
|
|
|
|
if (__nleft == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
const std::streamsize __off = __ret - __n1_left;
|
|
|
|
if (__off >= 0)
|
2004-02-12 19:24:07 +01:00
|
|
|
{
|
2004-02-18 09:36:27 +01:00
|
|
|
__nleft -= xwrite(__fd, __s2 + __off, __n2 - __off);
|
|
|
|
break;
|
2004-02-12 19:24:07 +01:00
|
|
|
}
|
2004-02-18 09:36:27 +01:00
|
|
|
|
|
|
|
__s1 += __ret;
|
|
|
|
__n1_left -= __ret;
|
2004-02-12 19:24:07 +01:00
|
|
|
}
|
|
|
|
|
2004-02-18 09:36:27 +01:00
|
|
|
return __n1 + __n2 - __nleft;
|
2004-02-12 19:24:07 +01:00
|
|
|
}
|
|
|
|
#endif
|
2006-09-12 19:48:45 +02:00
|
|
|
} // anonymous namespace
|
2004-02-05 06:24:18 +01:00
|
|
|
|
2005-12-19 01:56:05 +01:00
|
|
|
|
|
|
|
_GLIBCXX_BEGIN_NAMESPACE(std)
|
|
|
|
|
2002-02-12 05:35:58 +01:00
|
|
|
// Definitions for __basic_file<char>.
|
|
|
|
__basic_file<char>::__basic_file(__c_lock* /*__lock*/)
|
|
|
|
: _M_cfile(NULL), _M_cfile_created(false) { }
|
|
|
|
|
|
|
|
__basic_file<char>::~__basic_file()
|
2002-04-16 02:45:36 +02:00
|
|
|
{ this->close(); }
|
2002-02-12 05:35:58 +01:00
|
|
|
|
|
|
|
__basic_file<char>*
|
2002-04-16 02:45:36 +02:00
|
|
|
__basic_file<char>::sys_open(__c_file* __file, ios_base::openmode)
|
2002-02-12 05:35:58 +01:00
|
|
|
{
|
|
|
|
__basic_file* __ret = NULL;
|
|
|
|
if (!this->is_open() && __file)
|
|
|
|
{
|
2004-08-30 13:33:54 +02:00
|
|
|
int __err;
|
|
|
|
errno = 0;
|
|
|
|
do
|
|
|
|
__err = this->sync();
|
|
|
|
while (__err && errno == EINTR);
|
|
|
|
if (!__err)
|
|
|
|
{
|
|
|
|
_M_cfile = __file;
|
|
|
|
_M_cfile_created = false;
|
|
|
|
__ret = this;
|
|
|
|
}
|
2002-04-30 21:04:43 +02:00
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
__basic_file<char>*
|
2003-12-07 04:46:14 +01:00
|
|
|
__basic_file<char>::sys_open(int __fd, ios_base::openmode __mode)
|
2002-04-30 21:04:43 +02:00
|
|
|
{
|
|
|
|
__basic_file* __ret = NULL;
|
2006-09-12 19:48:45 +02:00
|
|
|
const char* __c_mode = fopen_mode(__mode);
|
2004-04-07 05:33:36 +02:00
|
|
|
if (__c_mode && !this->is_open() && (_M_cfile = fdopen(__fd, __c_mode)))
|
2002-04-30 21:04:43 +02:00
|
|
|
{
|
2004-04-07 05:33:36 +02:00
|
|
|
char* __buf = NULL;
|
2003-12-07 04:46:14 +01:00
|
|
|
_M_cfile_created = true;
|
2002-04-30 21:04:43 +02:00
|
|
|
if (__fd == 0)
|
2004-04-07 05:33:36 +02:00
|
|
|
setvbuf(_M_cfile, __buf, _IONBF, 0);
|
2002-02-12 05:35:58 +01:00
|
|
|
__ret = this;
|
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
__basic_file<char>*
|
|
|
|
__basic_file<char>::open(const char* __name, ios_base::openmode __mode,
|
|
|
|
int /*__prot*/)
|
|
|
|
{
|
|
|
|
__basic_file* __ret = NULL;
|
2006-09-12 19:48:45 +02:00
|
|
|
const char* __c_mode = fopen_mode(__mode);
|
2004-02-05 06:24:18 +01:00
|
|
|
if (__c_mode && !this->is_open())
|
2002-02-12 05:35:58 +01:00
|
|
|
{
|
2003-10-22 17:51:55 +02:00
|
|
|
#ifdef _GLIBCXX_USE_LFS
|
|
|
|
if ((_M_cfile = fopen64(__name, __c_mode)))
|
|
|
|
#else
|
2002-02-12 05:35:58 +01:00
|
|
|
if ((_M_cfile = fopen(__name, __c_mode)))
|
2003-10-22 17:51:55 +02:00
|
|
|
#endif
|
2002-02-12 05:35:58 +01:00
|
|
|
{
|
|
|
|
_M_cfile_created = true;
|
|
|
|
__ret = this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2002-04-30 21:04:43 +02:00
|
|
|
__basic_file<char>::is_open() const
|
|
|
|
{ return _M_cfile != 0; }
|
2002-02-12 05:35:58 +01:00
|
|
|
|
|
|
|
int
|
2002-04-30 21:04:43 +02:00
|
|
|
__basic_file<char>::fd()
|
2004-05-29 16:40:59 +02:00
|
|
|
{ return fileno(_M_cfile); }
|
|
|
|
|
|
|
|
__c_file*
|
|
|
|
__basic_file<char>::file()
|
|
|
|
{ return _M_cfile; }
|
2002-02-12 05:35:58 +01:00
|
|
|
|
|
|
|
__basic_file<char>*
|
|
|
|
__basic_file<char>::close()
|
|
|
|
{
|
2003-12-07 04:46:14 +01:00
|
|
|
__basic_file* __ret = static_cast<__basic_file*>(NULL);
|
2002-04-16 02:45:36 +02:00
|
|
|
if (this->is_open())
|
|
|
|
{
|
2004-09-17 10:42:07 +02:00
|
|
|
int __err = 0;
|
2003-04-11 04:57:44 +02:00
|
|
|
if (_M_cfile_created)
|
2004-09-17 10:42:07 +02:00
|
|
|
{
|
|
|
|
// In general, no need to zero errno in advance if checking
|
|
|
|
// for error first. However, C89/C99 (at variance with IEEE
|
|
|
|
// 1003.1, f.i.) do not mandate that fclose must set errno
|
|
|
|
// upon error.
|
|
|
|
errno = 0;
|
|
|
|
do
|
|
|
|
__err = fclose(_M_cfile);
|
|
|
|
while (__err && errno == EINTR);
|
|
|
|
}
|
|
|
|
_M_cfile = 0;
|
2004-08-30 13:33:54 +02:00
|
|
|
if (!__err)
|
|
|
|
__ret = this;
|
2002-04-16 02:45:36 +02:00
|
|
|
}
|
2003-12-07 04:46:14 +01:00
|
|
|
return __ret;
|
2002-02-12 05:35:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
streamsize
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 06:20:57 +02:00
|
|
|
__basic_file<char>::xsgetn(char* __s, streamsize __n)
|
2003-07-04 23:24:35 +02:00
|
|
|
{
|
|
|
|
streamsize __ret;
|
|
|
|
do
|
|
|
|
__ret = read(this->fd(), __s, __n);
|
|
|
|
while (__ret == -1L && errno == EINTR);
|
|
|
|
return __ret;
|
|
|
|
}
|
2004-02-12 01:05:35 +01:00
|
|
|
|
|
|
|
streamsize
|
|
|
|
__basic_file<char>::xsputn(const char* __s, streamsize __n)
|
2006-09-12 19:48:45 +02:00
|
|
|
{ return xwrite(this->fd(), __s, __n); }
|
2003-07-04 09:14:54 +02:00
|
|
|
|
2003-07-14 20:23:12 +02:00
|
|
|
streamsize
|
|
|
|
__basic_file<char>::xsputn_2(const char* __s1, streamsize __n1,
|
|
|
|
const char* __s2, streamsize __n2)
|
|
|
|
{
|
|
|
|
streamsize __ret = 0;
|
|
|
|
#ifdef _GLIBCXX_HAVE_WRITEV
|
2006-09-12 19:48:45 +02:00
|
|
|
__ret = xwritev(this->fd(), __s1, __n1, __s2, __n2);
|
2003-07-14 20:23:12 +02:00
|
|
|
#else
|
|
|
|
if (__n1)
|
2006-09-12 19:48:45 +02:00
|
|
|
__ret = xwrite(this->fd(), __s1, __n1);
|
2003-07-14 20:23:12 +02:00
|
|
|
|
|
|
|
if (__ret == __n1)
|
2006-09-12 19:48:45 +02:00
|
|
|
__ret += xwrite(this->fd(), __s2, __n2);
|
2003-07-14 20:23:12 +02:00
|
|
|
#endif
|
|
|
|
return __ret;
|
|
|
|
}
|
|
|
|
|
2003-10-17 00:37:53 +02:00
|
|
|
streamoff
|
2003-10-02 22:37:06 +02:00
|
|
|
__basic_file<char>::seekoff(streamoff __off, ios_base::seekdir __way)
|
2003-10-22 17:51:55 +02:00
|
|
|
{
|
|
|
|
#ifdef _GLIBCXX_USE_LFS
|
|
|
|
return lseek64(this->fd(), __off, __way);
|
|
|
|
#else
|
2004-09-21 11:06:08 +02:00
|
|
|
if (__off > numeric_limits<off_t>::max()
|
|
|
|
|| __off < numeric_limits<off_t>::min())
|
2003-10-22 17:51:55 +02:00
|
|
|
return -1L;
|
|
|
|
return lseek(this->fd(), __off, __way);
|
|
|
|
#endif
|
|
|
|
}
|
2003-07-04 09:14:54 +02:00
|
|
|
|
2002-02-12 05:35:58 +01:00
|
|
|
int
|
2002-04-30 21:04:43 +02:00
|
|
|
__basic_file<char>::sync()
|
|
|
|
{ return fflush(_M_cfile); }
|
2003-03-28 19:28:47 +01:00
|
|
|
|
|
|
|
streamsize
|
[multiple changes]
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9027
PR libstdc++/9520
PR libstdc++/10096
* include/bits/fstream.tcc (basic_file::_M_underflow): Add generic
implementation, based on old wchar_t specialization, add support
for codecvt::in() return value of codecvt_base::noconv, remove
_M_file.sys_ungetc() call.
* include/std/std_fstream.h (basic_file::underflow,
basic_file::uflow, basic_file::_M_underflow): Remove
specialization declarations, call _M_underflow from generic versions
of underflow and uflow.
* src/fstream.cc (basic_file::underflow, basic_file::uflow,
basic_file::_M_underflow): Remove specializations.
* src/Makefile.am (sources): Remove fstream.cc.
* src/Makefile.in: Regenerated.
* testsuite/27_io/basic_filebuf/underflow/10096.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/1.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/char/9027.cc: New test.
* testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc: New test.
2003-05-10 Benjamin Kosnik <bkoz@redhat.com>
* include/ext/stdio_filebuf.h (__stdio_filebuf): Remove stack
buffer.
* config/io/basic_file_stdio.h (__basic_file::xsgetn): Remove
unbuffered bits.
(__basic_file::xsputn): Same.
(__basic_file::seekoff): Same.
(__basic_file::seekpos): Same.
(__basic_file::showmanyc): Same.
* config/io/basic_file_stdio.cc: Same.
* include/std/std_fstream.h: Same.
* include/bits/fstream.tcc: Same.
* src/fstream.cc: Same.
* testsuite/27_io/basic_filebuf/sgetn/char/1.cc (test05): Tidy.
2003-05-10 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/9520
PR libstdc++/9661
PR libstdc++/9662
* include/ext/stdio_sync_filebuf.h: New file.
(basic_stdiobuf): New.
* include/Makefile.am (ext_headers): Add ext/stdio_sync_filebuf.h
* include/Makefile.in: Regenerate.
* include/bits/ios_base.h (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove declarations.
* src/globals.cc (buf_cout_sync, buf_cin_sync, buf_cerr_sync,
buf_wcout_sync, buf_wcin_sync, buf_wcerr_sync): Define.
* src/ios.cc (Init::_S_create_buffers,
Init::_S_destroy_buffers): Remove.
(Init::Init): Create and use syncronized buffers.
(ios_base::sync_with_stdio): Destroy syncronized buffers,
create and install unsyncronized buffers.
* testsuite/27_io/objects/char/10.cc: New test.
* testsuite/27_io/objects/char/9.cc: New test.
* testsuite/27_io/objects/char/9661-1.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.cc: New test.
* testsuite/27_io/objects/char/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/1.cc: New test.
* testsuite/27_io/objects/wchar_t/10.cc: New test.
* testsuite/27_io/objects/wchar_t/2.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/2523-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/2523-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/3045.cc: New test.
* testsuite/27_io/objects/wchar_t/3647.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/3_xin.in: New.
* testsuite/27_io/objects/wchar_t/4_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/4_xin.in: New.
* testsuite/27_io/objects/wchar_t/5.cc: New test.
* testsuite/27_io/objects/wchar_t/5268.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/5280_xin.in: New.
* testsuite/27_io/objects/wchar_t/6.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6548_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-1_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-1_xin.in: New.
* testsuite/27_io/objects/wchar_t/6648-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/6648-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/7.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/7744_xin.in: New.
* testsuite/27_io/objects/wchar_t/8.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9_xin.in: New.
* testsuite/27_io/objects/wchar_t/9520.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-1.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.cc: New test.
* testsuite/27_io/objects/wchar_t/9661-2_xin.in: New.
* testsuite/27_io/objects/wchar_t/9662.cc: New test.
* testsuite/ext/stdiobuf_char.cc: New test.
* testsuite/ext/stdiobuf_wchar_t.cc: New test.
From-SVN: r66678
2003-05-11 06:20:57 +02:00
|
|
|
__basic_file<char>::showmanyc()
|
2003-03-28 19:28:47 +01:00
|
|
|
{
|
|
|
|
#ifdef FIONREAD
|
|
|
|
// Pipes and sockets.
|
2004-02-05 21:11:32 +01:00
|
|
|
#ifdef _GLIBCXX_FIONREAD_TAKES_OFF_T
|
|
|
|
off_t __num = 0;
|
|
|
|
#else
|
2003-03-28 19:28:47 +01:00
|
|
|
int __num = 0;
|
2004-02-05 21:11:32 +01:00
|
|
|
#endif
|
2003-03-28 19:28:47 +01:00
|
|
|
int __r = ioctl(this->fd(), FIONREAD, &__num);
|
|
|
|
if (!__r && __num >= 0)
|
|
|
|
return __num;
|
|
|
|
#endif
|
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#ifdef _GLIBCXX_HAVE_POLL
|
2003-03-28 19:28:47 +01:00
|
|
|
// Cheap test.
|
|
|
|
struct pollfd __pfd[1];
|
|
|
|
__pfd[0].fd = this->fd();
|
|
|
|
__pfd[0].events = POLLIN;
|
|
|
|
if (poll(__pfd, 1, 0) <= 0)
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2003-07-05 06:05:45 +02:00
|
|
|
#if defined(_GLIBCXX_HAVE_S_ISREG) || defined(_GLIBCXX_HAVE_S_IFREG)
|
2003-03-28 19:28:47 +01:00
|
|
|
// Regular files.
|
2004-09-21 11:06:08 +02:00
|
|
|
#ifdef _GLIBCXX_USE_LFS
|
|
|
|
struct stat64 __buffer;
|
|
|
|
const int __err = fstat64(this->fd(), &__buffer);
|
|
|
|
if (!__err && _GLIBCXX_ISREG(__buffer.st_mode))
|
|
|
|
{
|
|
|
|
const streamoff __off = __buffer.st_size - lseek64(this->fd(), 0,
|
|
|
|
ios_base::cur);
|
|
|
|
return std::min(__off, streamoff(numeric_limits<streamsize>::max()));
|
|
|
|
}
|
|
|
|
#else
|
2003-03-28 19:28:47 +01:00
|
|
|
struct stat __buffer;
|
2004-09-21 11:06:08 +02:00
|
|
|
const int __err = fstat(this->fd(), &__buffer);
|
|
|
|
if (!__err && _GLIBCXX_ISREG(__buffer.st_mode))
|
|
|
|
return __buffer.st_size - lseek(this->fd(), 0, ios_base::cur);
|
|
|
|
#endif
|
2003-03-28 19:28:47 +01:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
2005-12-19 01:56:05 +01:00
|
|
|
|
|
|
|
_GLIBCXX_END_NAMESPACE
|
|
|
|
|