]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/html/manual/bk01pt12ch38.html
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / html / manual / bk01pt12ch38.html
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 38. Input and Output</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="&#10;      ISO C++&#10;    , &#10;      library&#10;    " /><link rel="start" href="../spine.html" title="The GNU C++ Library Documentation" /><link rel="up" href="extensions.html" title="Part XII. Extensions" /><link rel="prev" href="bk01pt12ch37.html" title="Chapter 37. Iterators" /><link rel="next" href="bk01pt12ch39.html" title="Chapter 39. Demangling" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 38. Input and Output</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk01pt12ch37.html">Prev</a> </td><th width="60%" align="center">Part XII. Extensions</th><td width="20%" align="right"> <a accesskey="n" href="bk01pt12ch39.html">Next</a></td></tr></table><hr /></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="manual.ext.io"></a>Chapter 38. Input and Output</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="bk01pt12ch38.html#manual.ext.io.filebuf_derived">Derived filebufs</a></span></dt></dl></div><p>
4     Extensions allowing <code class="code">filebuf</code>s to be constructed from
5     "C" types like  FILE*s and file descriptors.
6   </p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="manual.ext.io.filebuf_derived"></a>Derived filebufs</h2></div></div></div><p>The v2 library included non-standard extensions to construct
7       <code class="code">std::filebuf</code>s from C stdio types such as
8       <code class="code">FILE*</code>s and POSIX file descriptors.
9       Today the recommended way to use stdio types with libstdc++
10       IOStreams is via the <code class="code">stdio_filebuf</code> class (see below),
11       but earlier releases provided slightly different mechanisms.
12    </p><div class="itemizedlist"><ul type="disc"><li><p>3.0.x <code class="code">filebuf</code>s have another ctor with this signature:
13         <code class="code">basic_filebuf(__c_file_type*, ios_base::openmode, int_type);
14         </code>
15          This comes in very handy in a number of places, such as
16          attaching Unix sockets, pipes, and anything else which uses file
17          descriptors, into the IOStream buffering classes.  The three
18          arguments are as follows:
19          </p><div class="itemizedlist"><ul type="circle"><li><p><code class="code">__c_file_type*      F   </code>
20               // the __c_file_type typedef usually boils down to stdio's FILE
21           </p></li><li><p><code class="code">ios_base::openmode  M   </code>
22               // same as all the other uses of openmode
23           </p></li><li><p><code class="code">int_type            B   </code>
24               // buffer size, defaults to BUFSIZ if not specified
25           </p></li></ul></div><p>
26          For those wanting to use file descriptors instead of FILE*'s, I
27          invite you to contemplate the mysteries of C's <code class="code">fdopen()</code>.
28      </p></li><li><p>In library snapshot 3.0.95 and later, <code class="code">filebuf</code>s bring
29          back an old extension:  the <code class="code">fd()</code> member function.  The
30          integer returned from this function can be used for whatever file
31          descriptors can be used for on your platform.  Naturally, the
32          library cannot track what you do on your own with a file descriptor,
33          so if you perform any I/O directly, don't expect the library to be
34          aware of it.
35      </p></li><li><p>Beginning with 3.1, the extra <code class="code">filebuf</code> constructor and
36          the <code class="code">fd()</code> function were removed from the standard
37          filebuf.  Instead, <code class="code">&lt;ext/stdio_filebuf.h&gt;</code> contains
38          a derived class called
39          <a class="ulink" href="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/class____gnu__cxx_1_1stdio__filebuf.html" target="_top"><code class="code">__gnu_cxx::stdio_filebuf</code></a>.
40          This class can be constructed from a C <code class="code">FILE*</code> or a file
41          descriptor, and provides the <code class="code">fd()</code> function.
42      </p></li></ul></div><p>If you want to access a <code class="code">filebuf</code>'s file descriptor to
43       implement file locking (e.g. using the <code class="code">fcntl()</code> system
44       call) then you might be interested in Henry Suter's
45       <a class="ulink" href="http://suter.home.cern.ch/suter/RWLock.html" target="_top">RWLock</a>
46       class.
47    </p><p>
48     </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk01pt12ch37.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="extensions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk01pt12ch39.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 37. Iterators </td><td width="20%" align="center"><a accesskey="h" href="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 39. Demangling</td></tr></table></div></body></html>