1 |
742 |
jeremybenn |
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2 |
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
3 |
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Chapter 28. Input and Output</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"/><meta name="keywords" content=" ISO C++ , library "/><meta name="keywords" content=" ISO C++ , runtime , library "/><link rel="home" href="../index.html" title="The GNU C++ Library"/><link rel="up" href="extensions.html" title="Part III. Extensions"/><link rel="prev" href="ext_iterators.html" title="Chapter 27. Iterators"/><link rel="next" href="ext_demangling.html" title="Chapter 29. Demangling"/></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 28. Input and Output</th></tr><tr><td align="left"><a accesskey="p" href="ext_iterators.html">Prev</a> </td><th width="60%" align="center">Part III.
|
4 |
|
|
Extensions
|
5 |
|
|
|
6 |
|
|
</th><td align="right"> <a accesskey="n" href="ext_demangling.html">Next</a></td></tr></table><hr/></div><div class="chapter" title="Chapter 28. Input and Output"><div class="titlepage"><div><div><h2 class="title"><a id="manual.ext.io"/>Chapter 28. Input and Output</h2></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl><dt><span class="section"><a href="ext_io.html#manual.ext.io.filebuf_derived">Derived filebufs</a></span></dt></dl></div><p>
|
7 |
|
|
Extensions allowing <code class="code">filebuf</code>s to be constructed from
|
8 |
|
|
"C" types like FILE*s and file descriptors.
|
9 |
|
|
</p><div class="section" title="Derived filebufs"><div class="titlepage"><div><div><h2 class="title"><a id="manual.ext.io.filebuf_derived"/>Derived filebufs</h2></div></div></div><p>The v2 library included non-standard extensions to construct
|
10 |
|
|
<code class="code">std::filebuf</code>s from C stdio types such as
|
11 |
|
|
<code class="code">FILE*</code>s and POSIX file descriptors.
|
12 |
|
|
Today the recommended way to use stdio types with libstdc++
|
13 |
|
|
IOStreams is via the <code class="code">stdio_filebuf</code> class (see below),
|
14 |
|
|
but earlier releases provided slightly different mechanisms.
|
15 |
|
|
</p><div class="itemizedlist"><ul class="itemizedlist"><li class="listitem"><p>3.0.x <code class="code">filebuf</code>s have another ctor with this signature:
|
16 |
|
|
<code class="code">basic_filebuf(__c_file_type*, ios_base::openmode, int_type);
|
17 |
|
|
</code>
|
18 |
|
|
This comes in very handy in a number of places, such as
|
19 |
|
|
attaching Unix sockets, pipes, and anything else which uses file
|
20 |
|
|
descriptors, into the IOStream buffering classes. The three
|
21 |
|
|
arguments are as follows:
|
22 |
|
|
</p><div class="itemizedlist"><ul class="itemizedlist"><li class="listitem"><p><code class="code">__c_file_type* F </code>
|
23 |
|
|
// the __c_file_type typedef usually boils down to stdio's FILE
|
24 |
|
|
</p></li><li class="listitem"><p><code class="code">ios_base::openmode M </code>
|
25 |
|
|
// same as all the other uses of openmode
|
26 |
|
|
</p></li><li class="listitem"><p><code class="code">int_type B </code>
|
27 |
|
|
// buffer size, defaults to BUFSIZ if not specified
|
28 |
|
|
</p></li></ul></div><p>
|
29 |
|
|
For those wanting to use file descriptors instead of FILE*'s, I
|
30 |
|
|
invite you to contemplate the mysteries of C's <code class="code">fdopen()</code>.
|
31 |
|
|
</p></li><li class="listitem"><p>In library snapshot 3.0.95 and later, <code class="code">filebuf</code>s bring
|
32 |
|
|
back an old extension: the <code class="code">fd()</code> member function. The
|
33 |
|
|
integer returned from this function can be used for whatever file
|
34 |
|
|
descriptors can be used for on your platform. Naturally, the
|
35 |
|
|
library cannot track what you do on your own with a file descriptor,
|
36 |
|
|
so if you perform any I/O directly, don't expect the library to be
|
37 |
|
|
aware of it.
|
38 |
|
|
</p></li><li class="listitem"><p>Beginning with 3.1, the extra <code class="code">filebuf</code> constructor and
|
39 |
|
|
the <code class="code">fd()</code> function were removed from the standard
|
40 |
|
|
filebuf. Instead, <code class="code"><ext/stdio_filebuf.h></code> contains
|
41 |
|
|
a derived class called
|
42 |
|
|
<a class="link" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00074.html"><code class="code">__gnu_cxx::stdio_filebuf</code></a>.
|
43 |
|
|
This class can be constructed from a C <code class="code">FILE*</code> or a file
|
44 |
|
|
descriptor, and provides the <code class="code">fd()</code> function.
|
45 |
|
|
</p></li></ul></div></div></div><div class="navfooter"><hr/><table width="100%" summary="Navigation footer"><tr><td align="left"><a accesskey="p" href="ext_iterators.html">Prev</a> </td><td align="center"><a accesskey="u" href="extensions.html">Up</a></td><td align="right"> <a accesskey="n" href="ext_demangling.html">Next</a></td></tr><tr><td align="left" valign="top">Chapter 27. Iterators </td><td align="center"><a accesskey="h" href="../index.html">Home</a></td><td align="right" valign="top"> Chapter 29. Demangling</td></tr></table></div></body></html>
|