summaryrefslogtreecommitdiffstats
path: root/contrib/libstdc++/config/io
diff options
context:
space:
mode:
authorkan <kan@FreeBSD.org>2003-07-11 03:42:04 +0000
committerkan <kan@FreeBSD.org>2003-07-11 03:42:04 +0000
commitc7bbbdd036d3dd7ae253fb13c9994215af06f073 (patch)
treece14546aca3a67fa3440aed52f132bafaf68fe70 /contrib/libstdc++/config/io
parentb2a8872fbe1ec1c49094559ac7b78e6ea4ab7180 (diff)
downloadFreeBSD-src-c7bbbdd036d3dd7ae253fb13c9994215af06f073.zip
FreeBSD-src-c7bbbdd036d3dd7ae253fb13c9994215af06f073.tar.gz
Gcc 3.3.1-pre 2003-07-11 C++ support bits.
Diffstat (limited to 'contrib/libstdc++/config/io')
-rw-r--r--contrib/libstdc++/config/io/basic_file_stdio.cc118
-rw-r--r--contrib/libstdc++/config/io/basic_file_stdio.h3
2 files changed, 103 insertions, 18 deletions
diff --git a/contrib/libstdc++/config/io/basic_file_stdio.cc b/contrib/libstdc++/config/io/basic_file_stdio.cc
index 93ca6bc..5393a14 100644
--- a/contrib/libstdc++/config/io/basic_file_stdio.cc
+++ b/contrib/libstdc++/config/io/basic_file_stdio.cc
@@ -32,6 +32,31 @@
//
#include <bits/basic_file.h>
+#include <fcntl.h>
+#include <unistd.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
{
@@ -43,8 +68,8 @@ namespace std
{ this->close(); }
void
- __basic_file<char>::_M_open_mode(ios_base::openmode __mode, int&, int&,
- char* __c_mode)
+ __basic_file<char>::_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;
@@ -52,18 +77,39 @@ namespace std
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");
+ {
+ strcpy(__c_mode, "w");
+ __p_mode = (O_WRONLY | O_CREAT);
+ }
if (!__testi && __testo && !__testt && __testa)
- strcpy(__c_mode, "a");
+ {
+ strcpy(__c_mode, "a");
+ __p_mode |= O_WRONLY | O_CREAT | O_APPEND;
+ }
if (!__testi && __testo && __testt && !__testa)
- strcpy(__c_mode, "w");
+ {
+ strcpy(__c_mode, "w");
+ __p_mode |= O_WRONLY | O_CREAT | O_TRUNC;
+ }
+
if (__testi && !__testo && !__testt && !__testa)
- strcpy(__c_mode, "r");
+ {
+ strcpy(__c_mode, "r");
+ __p_mode |= O_RDONLY;
+ }
if (__testi && __testo && !__testt && !__testa)
- strcpy(__c_mode, "r+");
+ {
+ strcpy(__c_mode, "r+");
+ __p_mode |= O_RDWR | O_CREAT;
+ }
if (__testi && __testo && __testt && !__testa)
- strcpy(__c_mode, "w+");
+ {
+ strcpy(__c_mode, "w+");
+ __p_mode |= O_RDWR | O_CREAT | O_TRUNC;
+ }
if (__testb)
strcat(__c_mode, "b");
}
@@ -148,12 +194,12 @@ namespace std
__basic_file* __retval = static_cast<__basic_file*>(NULL);
if (this->is_open())
{
- fflush(_M_cfile);
- if ((_M_cfile_created && fclose(_M_cfile) == 0) || !_M_cfile_created)
- {
- _M_cfile = 0;
- __retval = this;
- }
+ if (_M_cfile_created)
+ fclose(_M_cfile);
+ else
+ fflush(_M_cfile);
+ _M_cfile = 0;
+ __retval = this;
}
return __retval;
}
@@ -170,18 +216,54 @@ namespace std
__basic_file<char>::seekoff(streamoff __off, ios_base::seekdir __way,
ios_base::openmode /*__mode*/)
{
- fseek(_M_cfile, __off, __way);
- return ftell(_M_cfile);
+ 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*/)
{
- fseek(_M_cfile, __pos, ios_base::beg);
- return ftell(_M_cfile);
+ if (!fseek(_M_cfile, __pos, ios_base::beg))
+ return ftell(_M_cfile);
+ else
+ // Fseek failed.
+ return -1L;
}
int
__basic_file<char>::sync()
{ return fflush(_M_cfile); }
+
+ streamsize
+ __basic_file<char>::showmanyc_helper()
+ {
+#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))
+ return __buffer.st_size - ftell(_M_cfile);
+#endif
+ return 0;
+ }
} // namespace std
diff --git a/contrib/libstdc++/config/io/basic_file_stdio.h b/contrib/libstdc++/config/io/basic_file_stdio.h
index fe6edbb..cefd38f 100644
--- a/contrib/libstdc++/config/io/basic_file_stdio.h
+++ b/contrib/libstdc++/config/io/basic_file_stdio.h
@@ -108,6 +108,9 @@ namespace std
int
sync();
+
+ streamsize
+ showmanyc_helper();
};
} // namespace std
OpenPOWER on IntegriCloud