summaryrefslogtreecommitdiff
path: root/libstdc++-v3/config
diff options
context:
space:
mode:
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-03-28 18:28:47 +0000
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>2003-03-28 18:28:47 +0000
commit3a2785797d761c76ad5f4b335eb145c9dbf580b8 (patch)
tree87d4905b8b4194c68ef7eadde4923aafabeee4eb /libstdc++-v3/config
parent32351c925cead89ad3b7086725683ba4b2bc9e44 (diff)
downloadgcc-3a2785797d761c76ad5f4b335eb145c9dbf580b8.tar.gz
2003-03-28 Paolo Carlini <pcarlini@unitus.it>
Nathan Myers <ncm@cantrip.org> PR libstdc++/9533 * include/bits/fstream.tcc (basic_filebuf<>::open): Don't call underflow(). (basic_filebuf<>::showmanyc): Use the information provided by codecvt and __basic_file<>::showmanyc_helper to implement a non-trivial showmanyc. * config/io/basic_file_stdio.h (__basic_file<>::showmanyc_helper): New, declare. * config/io/basic_file_stdio.cc (__basic_file<>::showmanyc_helper): Define. (__basic_file<>::_M_open_mode): Don't set O_NONBLOCK. (__basic_file<char>::open): Don't call fcntl(). * acinclude.m4 (GLIBCPP_CHECK_S_ISREG_OR_S_IFREG, GLIBCPP_CHECK_POLL): New macros. * configure.in: Call here. * acconfig.h: Add #undefs for the corresponding symbols. * aclocal.m4: Regenerate. * configure: Regenerate. * config.h.in: Regenerate. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@64978 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/config')
-rw-r--r--libstdc++-v3/config/io/basic_file_stdio.cc68
-rw-r--r--libstdc++-v3/config/io/basic_file_stdio.h3
2 files changed, 60 insertions, 11 deletions
diff --git a/libstdc++-v3/config/io/basic_file_stdio.cc b/libstdc++-v3/config/io/basic_file_stdio.cc
index 7f4c909e574..b2287b24f7f 100644
--- a/libstdc++-v3/config/io/basic_file_stdio.cc
+++ b/libstdc++-v3/config/io/basic_file_stdio.cc
@@ -36,6 +36,29 @@
#include <unistd.h>
#include <errno.h>
+#ifdef _GLIBCPP_HAVE_SYS_IOCTL_H
+#define BSD_COMP /* Get FIONREAD on Solaris2. */
+#include <sys/ioctl.h>
+#endif
+
+// Pick up FIONREAD on Solaris 2.5.
+#ifdef _GLIBCPP_HAVE_SYS_FILIO_H
+#include <sys/filio.h>
+#endif
+
+#ifdef _GLIBCPP_HAVE_POLL
+#include <poll.h>
+#endif
+
+#if defined(_GLIBCPP_HAVE_S_ISREG) || defined(_GLIBCPP_HAVE_S_IFREG)
+# include <sys/stat.h>
+# ifdef _GLIBCPP_HAVE_S_ISREG
+# define _GLIBCPP_ISREG(x) S_ISREG(x)
+# else
+# define _GLIBCPP_ISREG(x) (((x) & S_IFMT) == S_IFREG)
+# endif
+#endif
+
namespace std
{
// Definitions for __basic_file<char>.
@@ -76,11 +99,7 @@ namespace std
if (__testi && !__testo && !__testt && !__testa)
{
strcpy(__c_mode, "r");
-#if defined (O_NONBLOCK)
- __p_mode |= O_RDONLY | O_NONBLOCK;
-#else
__p_mode |= O_RDONLY;
-#endif
}
if (__testi && __testo && !__testt && !__testa)
{
@@ -156,13 +175,6 @@ namespace std
if ((_M_cfile = fopen(__name, __c_mode)))
{
_M_cfile_created = true;
-
-#if defined (F_SETFL) && defined (O_NONBLOCK)
- // Set input to nonblocking for fifos.
- if (__mode & ios_base::in)
- fcntl(this->fd(), F_SETFL, O_NONBLOCK);
-#endif
-
__ret = this;
}
}
@@ -261,4 +273,38 @@ namespace std
int
__basic_file<char>::sync()
{ return fflush(_M_cfile); }
+
+ streamsize
+ __basic_file<char>::showmanyc_helper(bool __stdio)
+ {
+#ifdef FIONREAD
+ // Pipes and sockets.
+ int __num = 0;
+ int __r = ioctl(this->fd(), FIONREAD, &__num);
+ if (!__r && __num >= 0)
+ return __num;
+#endif
+
+#ifdef _GLIBCPP_HAVE_POLL
+ // Cheap test.
+ struct pollfd __pfd[1];
+ __pfd[0].fd = this->fd();
+ __pfd[0].events = POLLIN;
+ if (poll(__pfd, 1, 0) <= 0)
+ return 0;
+#endif
+
+#if defined(_GLIBCPP_HAVE_S_ISREG) || defined(_GLIBCPP_HAVE_S_IFREG)
+ // Regular files.
+ struct stat __buffer;
+ int __ret = fstat(this->fd(), &__buffer);
+ if (!__ret && _GLIBCPP_ISREG(__buffer.st_mode))
+ if (__stdio)
+ return __buffer.st_size - ftell(_M_cfile);
+ else
+ return __buffer.st_size - lseek(this->fd(), 0, ios_base::cur);
+#endif
+ return 0;
+ }
+
} // namespace std
diff --git a/libstdc++-v3/config/io/basic_file_stdio.h b/libstdc++-v3/config/io/basic_file_stdio.h
index b01e4a5db10..b6a05697612 100644
--- a/libstdc++-v3/config/io/basic_file_stdio.h
+++ b/libstdc++-v3/config/io/basic_file_stdio.h
@@ -108,6 +108,9 @@ namespace std
int
sync();
+
+ streamsize
+ showmanyc_helper(bool __stdio);
};
} // namespace std