diff options
author | Paolo Carlini <pcarlini@unitus.it> | 2003-03-09 23:31:45 +0100 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2003-03-09 22:31:45 +0000 |
commit | 95dca20c9c6f8f810efe1ab58c8c0f425415e715 (patch) | |
tree | 34ebb56add00d1c25c0e83fe8ea0ac6e0f46304e /libstdc++-v3/config/io | |
parent | f7b3ab8ae7588e4b502c4dd731ad6c472bb842ce (diff) | |
download | gcc-95dca20c9c6f8f810efe1ab58c8c0f425415e715.tar.gz |
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
Diffstat (limited to 'libstdc++-v3/config/io')
-rw-r--r-- | libstdc++-v3/config/io/basic_file_stdio.cc | 69 | ||||
-rw-r--r-- | libstdc++-v3/config/io/basic_file_stdio.h | 8 |
2 files changed, 57 insertions, 20 deletions
diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc index 961523b0dcd..881792e7f81 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, 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 @@ -33,6 +33,7 @@ #include <bits/basic_file.h> #include <fcntl.h> +#include <errno.h> namespace std { @@ -191,33 +192,69 @@ namespace std return __retval; } + // In the next four functions we want to use stdio functions only + // when synced with stdio (_M_buf_size == 1): I/O primitives do not + // block until the asked number of bytes are available. streamsize - __basic_file<char>::xsgetn(char* __s, streamsize __n) - { return fread(__s, 1, __n, _M_cfile); } - + __basic_file<char>::xsgetn(char* __s, streamsize __n, bool __stdio) + { + if (__stdio) + return fread(__s, 1, __n, _M_cfile); + else + { + streamsize __ret; + do + __ret = read(this->fd(), __s, __n); + while (__ret == -1L && errno == EINTR); + return __ret; + } + } + streamsize - __basic_file<char>::xsputn(const char* __s, streamsize __n) - { return fwrite(__s, 1, __n, _M_cfile); } + __basic_file<char>::xsputn(const char* __s, streamsize __n, bool __stdio) + { + if (__stdio) + return fwrite(__s, 1, __n, _M_cfile); + else + { + streamsize __ret; + do + __ret = write(this->fd(), __s, __n); + while (__ret == -1L && errno == EINTR); + return __ret; + } + } streamoff __basic_file<char>::seekoff(streamoff __off, ios_base::seekdir __way, - ios_base::openmode /*__mode*/) + bool __stdio, ios_base::openmode /*__mode*/) { - if (!fseek(_M_cfile, __off, __way)) - return ftell(_M_cfile); + if (!__stdio) + return lseek(this->fd(), __off, __way); else - // Fseek failed. - return -1L; + { + if (!fseek(_M_cfile, __off, __way)) + return ftell(_M_cfile); + else + // Fseek failed. + return -1L; + } } streamoff - __basic_file<char>::seekpos(streamoff __pos, ios_base::openmode /*__mode*/) + __basic_file<char>::seekpos(streamoff __pos, bool __stdio, + ios_base::openmode /*__mode*/) { - if (!fseek(_M_cfile, __pos, ios_base::beg)) - return ftell(_M_cfile); + if (!__stdio) + return lseek(this->fd(), __pos, ios_base::beg); else - // Fseek failed. - return -1L; + { + if (!fseek(_M_cfile, __pos, ios_base::beg)) + return ftell(_M_cfile); + else + // Fseek failed. + return -1L; + } } int diff --git a/libstdc++-v3/config/io/basic_file_stdio.h b/libstdc++-v3/config/io/basic_file_stdio.h index fe6edbb7058..b01e4a5db10 100644 --- a/libstdc++-v3/config/io/basic_file_stdio.h +++ b/libstdc++-v3/config/io/basic_file_stdio.h @@ -93,17 +93,17 @@ namespace std ~__basic_file(); streamsize - xsputn(const char* __s, streamsize __n); + xsputn(const char* __s, streamsize __n, bool __stdio); streamsize - xsgetn(char* __s, streamsize __n); + xsgetn(char* __s, streamsize __n, bool __stdio); streamoff - seekoff(streamoff __off, ios_base::seekdir __way, + seekoff(streamoff __off, ios_base::seekdir __way, bool __stdio, ios_base::openmode __mode = ios_base::in | ios_base::out); streamoff - seekpos(streamoff __pos, + seekpos(streamoff __pos, bool __stdio, ios_base::openmode __mode = ios_base::in | ios_base::out); int |