"add the iostream.h stub that contains fdbuf/ofdstream"
Brought to you by:
johnston
|
From: <ivt...@li...> - 2001-06-20 21:15:03
|
Patch: ivtools-010620-johnston-039
For: ivtools-0.9.4
Author: joh...@us...
Subject: add the iostream.h stub that contains fdbuf/ofdstream
Requires:
This is an intermediate patch to ivtools-0.9.4. To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:
patch -p0 <ThisFile
Summary of Changes:
- add the iostream.h stub that contains the fdbuf and ofdstream
classes for an ostream accessed by file descriptor.
Index: top_ivtools/MANIFEST
diff -c top_ivtools/MANIFEST:1.6 top_ivtools/MANIFEST:1.7
*** top_ivtools/MANIFEST:1.6 Fri Jun 15 16:24:50 2001
--- ./MANIFEST Wed Jun 20 14:12:01 2001
***************
*** 1537,1542 ****
--- 1537,1543 ----
ivtools-0.9/src/include/ivstd/Makefile
ivtools-0.9/src/include/ivstd/fstream.h
ivtools-0.9/src/include/ivstd/iosfwd
+ ivtools-0.9/src/include/ivstd/iostream.h
ivtools-0.9/src/include/ivstd/math.h
ivtools-0.9/src/include/ivstd/nan.h
ivtools-0.9/src/include/ivstd/osfcn.h
Index: include_std/iostream.h
diff -c /dev/null include_std/iostream.h:1.1
*** /dev/null Wed Jun 20 14:12:12 2001
--- src/include/ivstd/iostream.h Wed Jun 20 14:12:11 2001
***************
*** 0 ****
--- 1,45 ----
+ #ifndef _iv_iostream_h_
+ #define _iv_iostream_h_
+ #include_next <iostream.h>
+
+ #if __GNUG__>=3
+ #include <unistd.h>
+
+ // from a posting to lib...@gc... by Carlo Wood
+ // Quick and dirty unbuffered file descriptor streambuf.
+ class fdbuf : public std::basic_streambuf<char, std::char_traits<char> > {
+ public:
+ typedef std::char_traits<char> traits_type;
+ typedef traits_type::int_type int_type;
+ private:
+ int M_fd;
+ public:
+ fdbuf(int fd) : M_fd(fd) { }
+ protected:
+ virtual int_type overflow(int_type c = traits_type::eof())
+ {
+ if (!traits_type::eq_int_type(c, traits_type::eof()))
+ {
+ char cp[1];
+ *cp = c;
+ if (write(M_fd, cp, 1) != 1)
+ return traits_type::eof();
+ }
+ return 0;
+ }
+ // This would be needed if it was buffered.
+ // virtual std::streamsize xsputn(char const* s, std::streamsize num) { return write(M_fd, s, num); }
+ };
+
+ // Unbuffered file descriptor stream.
+ class ofdstream : public std::ostream {
+ private:
+ mutable fdbuf M_fdbuf;
+ public:
+ explicit
+ ofdstream(int fd) : std::ostream(&M_fdbuf), M_fdbuf(fd) { }
+ fdbuf* rdbuf(void) const { return &M_fdbuf; }
+ };
+ #endif
+
+ #endif
*** /dev/null Wed Jun 20 14:12:14 PDT 2001
--- patches/ivtools-010620-johnston-039
*************** patches/ivtools-010620-johnston-039
*** 0 ****
--- 1 ----
+ ivtools-010620-johnston-039
|