GNU extensions..

Carlo Wood carlo@alinoe.com
Tue Jun 19 06:12:00 GMT 2001


I already answered this, including example case, on the tuxCPProgramming
mailinglist where you asked the same question yesterday.  See below.

On Tue, Jun 19, 2001 at 02:15:05AM +0200, Roberto Diaz wrote:
> Hi!
> 
> I am very interested in this extension:
> 
> basic_filebuf(__c_file_type*, ios_base::openmode, int _type);
> 
> How stable can I expect to be this extension in the GNU libstdc++? it will
> be here with us till next month? year? :???
> 
> Any help would be hightly apprecciated!! thank you!
> 
> P.D. I am trying to figure out if there are some anyother tricks to have
> streams attached to a socket.. if you could help me with this.. thank you!
> 
> Regards
> 
> Roberto
> 
> ------------------------------------------------------------------------
> Roberto Diaz <rdiazmartin@vivaldi.dhis.org>
> http://vivaldi.dhis.org
> Powered by GNU running on a Linux kernel.
> Powered by Debian (The real wonder)
> 
> Concerto Grosso Op. 3/8 A minor
> Antonio Vivaldi (so... do you need beautiful words?)
> ------------------------------------------------------------------------

-- 
Carlo Wood <carlo@alinoe.com>


>From tuxCPProgramming-return-1838-39507973@listbot.com Tue Jun 19 03:32:10 2001
Return-Path: <tuxCPProgramming-return-1838-39507973@listbot.com>
Delivered-To: carlo@alinoe.com
Received: (qmail 25810 invoked by uid 0); 19 Jun 2001 03:32:09 -0000
Received: from unknown (HELO lbmail11.listbot.com) (unknown)
  by unknown with SMTP; 19 Jun 2001 03:32:09 -0000
Received: (qmail 49182 invoked by uid 0); 19 Jun 2001 03:37:05 -0000
Mailing-List: ListBot mailing list contact tuxCPProgramming-help@listbot.com
Delivered-To: mailing list tuxCPProgramming@listbot.com
Reply-To: "Linux C++ Programming" <tuxCPProgramming@listbot.com>
Received: (qmail 14396 invoked from network); 19 Jun 2001 03:41:15 -0000
Received: from node1500a.a2000.nl (HELO mail.alinoe.com) (24.132.80.10)
  by lb4.listbot.com with SMTP; 19 Jun 2001 03:41:15 -0000
Received: (qmail 25672 invoked by uid 500); 19 Jun 2001 03:30:31 -0000
Date: Tue, 19 Jun 2001 05:30:31 +0200
From: Carlo Wood <carlo@alinoe.com>
To: Linux C++ Programming <tuxCPProgramming@listbot.com>
Subject: Re: [LC++] annoying.. filebuf's
Message-ID: <20010619053031.A25442@alinoe.com>
Mail-Followup-To: Carlo Wood <carlo>,
	Linux C++ Programming <tuxCPProgramming@listbot.com>
References: < Pine.LNX.4.21.0106190348580.13961-100000@vivaldi.ddts.net >
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5i
In-Reply-To: < Pine.LNX.4.21.0106190348580.13961-100000@vivaldi.ddts.net >; from rdiazmartin@vivaldi.dhis.org on Tue, Jun 19, 2001 at 03:52:21AM +0200

Linux C++ Programming - http://users.senet.com.au/~lloy0076/linux_c_programming/

On Tue, Jun 19, 2001 at 03:52:21AM +0200, Roberto Diaz wrote:
> I had been wondering like a hell how could I attatch a file descriptor to
> a stream object.. I was looking at GNU extensions.. but now I find this:

Anything with fd is NOT portable and subject to be changed constantly.
The correct way to write your own streambuf derived class.  For example:


// 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; }
};


Regards,

-- 
Carlo Wood <carlo@alinoe.com>


______________________________________________________________________
To unsubscribe, write to tuxCPProgramming-unsubscribe@listbot.com



More information about the Libstdc++ mailing list