Files
pcp/man/html/group__Pcpstream.html
2014-02-20 21:02:52 +01:00

541 lines
34 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>libpcp: PCPSTREAMS</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">libpcp
&#160;<span id="projectnumber">0.2.1</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.2 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#nested-classes">Classes</a> &#124;
<a href="#typedef-members">Typedefs</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle">
<div class="title">PCPSTREAMS</div> </div>
</div><!--header-->
<div class="contents">
<p>I/O wrapper for files or buffers.
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct__pcp__stream__t.html">_pcp_stream_t</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">An I/O wrapper object backed by a file or a buffer. <a href="struct__pcp__stream__t.html#details">More...</a><br/></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
Typedefs</h2></td></tr>
<tr class="memitem:gaec72241f86d5391d5cae7477c66cdd73"><td class="memItemLeft" align="right" valign="top">typedef struct <a class="el" href="struct__pcp__stream__t.html">_pcp_stream_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a></td></tr>
<tr class="memdesc:gaec72241f86d5391d5cae7477c66cdd73"><td class="mdescLeft">&#160;</td><td class="mdescRight">The name used everywhere. <a href="#gaec72241f86d5391d5cae7477c66cdd73"></a><br/></td></tr>
<tr class="separator:gaec72241f86d5391d5cae7477c66cdd73"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga6733979d79704b2e3ce914662b0cebc8"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#ga6733979d79704b2e3ce914662b0cebc8">ps_new_file</a> (FILE *backendfd)</td></tr>
<tr class="memdesc:ga6733979d79704b2e3ce914662b0cebc8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a new stream, backed with an open file. <a href="#ga6733979d79704b2e3ce914662b0cebc8"></a><br/></td></tr>
<tr class="separator:ga6733979d79704b2e3ce914662b0cebc8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1b50c92fdad290e59317af2404460662"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#ga1b50c92fdad290e59317af2404460662">ps_new_inbuffer</a> (<a class="el" href="group__Buffer.html#ga2460ea15a51a37433b5f2e1503667e8f">Buffer</a> *b)</td></tr>
<tr class="memdesc:ga1b50c92fdad290e59317af2404460662"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a new input stream, backed with filled a buffer. <a href="#ga1b50c92fdad290e59317af2404460662"></a><br/></td></tr>
<tr class="separator:ga1b50c92fdad290e59317af2404460662"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga13ec0245b579949e6d586e1817615d2e"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#ga13ec0245b579949e6d586e1817615d2e">ps_new_outbuffer</a> ()</td></tr>
<tr class="memdesc:ga13ec0245b579949e6d586e1817615d2e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a new output stream, backed with a buffer. <a href="#ga13ec0245b579949e6d586e1817615d2e"></a><br/></td></tr>
<tr class="separator:ga13ec0245b579949e6d586e1817615d2e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gacfede4b1e9fa1ce0ccd7a55379ff6f15"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#gacfede4b1e9fa1ce0ccd7a55379ff6f15">ps_read</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream, void *buf, size_t readbytes)</td></tr>
<tr class="memdesc:gacfede4b1e9fa1ce0ccd7a55379ff6f15"><td class="mdescLeft">&#160;</td><td class="mdescRight">Read bytes into the given buffer from the current stream. <a href="#gacfede4b1e9fa1ce0ccd7a55379ff6f15"></a><br/></td></tr>
<tr class="separator:gacfede4b1e9fa1ce0ccd7a55379ff6f15"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab8e98ef81e802a242fbdb788b4387873"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#gab8e98ef81e802a242fbdb788b4387873">ps_write</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream, void *buf, size_t writebytes)</td></tr>
<tr class="memdesc:gab8e98ef81e802a242fbdb788b4387873"><td class="mdescLeft">&#160;</td><td class="mdescRight">Write bytes from the given buffer into the current stream. <a href="#gab8e98ef81e802a242fbdb788b4387873"></a><br/></td></tr>
<tr class="separator:gab8e98ef81e802a242fbdb788b4387873"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gafd50eb5e9c8ba399e133b6029eca8856"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#gafd50eb5e9c8ba399e133b6029eca8856">ps_print</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream, const char *fmt,...)</td></tr>
<tr class="memdesc:gafd50eb5e9c8ba399e133b6029eca8856"><td class="mdescLeft">&#160;</td><td class="mdescRight">Write a formatted string to the stream. <a href="#gafd50eb5e9c8ba399e133b6029eca8856"></a><br/></td></tr>
<tr class="separator:gafd50eb5e9c8ba399e133b6029eca8856"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga72812698d6b6aca964c7289be41eccf8"><td class="memItemLeft" align="right" valign="top">size_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#ga72812698d6b6aca964c7289be41eccf8">ps_tell</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream)</td></tr>
<tr class="memdesc:ga72812698d6b6aca964c7289be41eccf8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Tell the current read or write offset. <a href="#ga72812698d6b6aca964c7289be41eccf8"></a><br/></td></tr>
<tr class="separator:ga72812698d6b6aca964c7289be41eccf8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga64bc34dfbc1b3951c3d62e82a1ae8c34"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__Buffer.html#ga2460ea15a51a37433b5f2e1503667e8f">Buffer</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#ga64bc34dfbc1b3951c3d62e82a1ae8c34">ps_buffer</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream)</td></tr>
<tr class="memdesc:ga64bc34dfbc1b3951c3d62e82a1ae8c34"><td class="mdescLeft">&#160;</td><td class="mdescRight">Access the Buffer backend pointer. <a href="#ga64bc34dfbc1b3951c3d62e82a1ae8c34"></a><br/></td></tr>
<tr class="separator:ga64bc34dfbc1b3951c3d62e82a1ae8c34"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4a68da22eca6e9bd854d54467a071d0a"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a">ps_close</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream)</td></tr>
<tr class="memdesc:ga4a68da22eca6e9bd854d54467a071d0a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Close the stream and frees allocated memory. <a href="#ga4a68da22eca6e9bd854d54467a071d0a"></a><br/></td></tr>
<tr class="separator:ga4a68da22eca6e9bd854d54467a071d0a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac845e4dc3677aeef5e4de343d3f8033d"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#gac845e4dc3677aeef5e4de343d3f8033d">ps_end</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream)</td></tr>
<tr class="memdesc:gac845e4dc3677aeef5e4de343d3f8033d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if EOF have been reached. <a href="#gac845e4dc3677aeef5e4de343d3f8033d"></a><br/></td></tr>
<tr class="separator:gac845e4dc3677aeef5e4de343d3f8033d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga97b83164ecda8fd66897863ec7976890"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__Pcpstream.html#ga97b83164ecda8fd66897863ec7976890">ps_err</a> (<a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *stream)</td></tr>
<tr class="memdesc:ga97b83164ecda8fd66897863ec7976890"><td class="mdescLeft">&#160;</td><td class="mdescRight">Check if an error occurred during a read or write operation. <a href="#ga97b83164ecda8fd66897863ec7976890"></a><br/></td></tr>
<tr class="separator:ga97b83164ecda8fd66897863ec7976890"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<p>I/O wrapper for files or buffers. </p>
<p>Simple wrapper around FILE streams or Buffers, depending how the user initialized them. The Pcpstream object behaves always the same and it doesn't matter how it's backed.</p>
<p>We use it in the lib, e.g. in the crypto routines. That way we can support blockwise crypto on buffers or files.</p>
<p>Streams are, just like iostreams in c++, either output or input mode.</p>
<p>Sample usage:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;stdio.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;stdlib.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;limits.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;pcp.h&gt;</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main() {</div>
<div class="line"> <span class="comment">/* create a file with &quot;encrypted&quot; data */</span></div>
<div class="line"> FILE *out, *in;</div>
<div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> clear[8] = <span class="stringliteral">&quot;ABCDEFGH&quot;</span>;</div>
<div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> key[8] = <span class="stringliteral">&quot;IxD8Lq1K&quot;</span>;</div>
<div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> crypt[8] = {0};</div>
<div class="line"> <span class="keywordtype">int</span> blocks = 8;</div>
<div class="line"> <span class="keywordtype">int</span> i = 0;</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">if</span>((out = fopen(<span class="stringliteral">&quot;teststream.out&quot;</span>, <span class="stringliteral">&quot;wb+&quot;</span>)) == NULL) {</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">&quot;oops, could not open file!\n&quot;</span>);</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="struct__pcp__stream__t.html" title="An I/O wrapper object backed by a file or a buffer.">Pcpstream</a> *pout = <a class="code" href="group__Pcpstream.html#ga6733979d79704b2e3ce914662b0cebc8" title="Create a new stream, backed with an open file.">ps_new_file</a>(out);</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* &quot;encrypt&quot; a couple of times into the file */</span></div>
<div class="line"> <span class="keywordflow">for</span>(i=0; i&lt;blocks; i++) {</div>
<div class="line"> memcpy(crypt, clear, 8);</div>
<div class="line"> <a class="code" href="group__UTILs.html#gaad81054336208b62739f1e20091213a6" title="XOR an input buffer with another buffer.">_xorbuf</a>(key, crypt, 8);</div>
<div class="line"> <a class="code" href="group__Pcpstream.html#gab8e98ef81e802a242fbdb788b4387873" title="Write bytes from the given buffer into the current stream.">ps_write</a>(pout, crypt, 8);</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a" title="Close the stream and frees allocated memory.">ps_close</a>(pout);</div>
<div class="line"> fclose(out);</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* read it in again using an in and an out stream */</span></div>
<div class="line"> <span class="keywordflow">if</span>((in = fopen(<span class="stringliteral">&quot;teststream.out&quot;</span>, <span class="stringliteral">&quot;rb&quot;</span>)) == NULL) {</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">&quot;oops, could not open file!\n&quot;</span>);</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="struct__pcp__stream__t.html" title="An I/O wrapper object backed by a file or a buffer.">Pcpstream</a> *pin = <a class="code" href="group__Pcpstream.html#ga6733979d79704b2e3ce914662b0cebc8" title="Create a new stream, backed with an open file.">ps_new_file</a>(in);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* we&#39;ll use this stream to put the &quot;decrypted&quot; data in.</span></div>
<div class="line"><span class="comment"> note, that this could be a file as well. */</span></div>
<div class="line"> <a class="code" href="struct__pcp__stream__t.html" title="An I/O wrapper object backed by a file or a buffer.">Pcpstream</a> *pclear = <a class="code" href="group__Pcpstream.html#ga13ec0245b579949e6d586e1817615d2e" title="Create a new output stream, backed with a buffer.">ps_new_outbuffer</a>();</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* read and &quot;decrypt&quot; */</span></div>
<div class="line"> <span class="keywordflow">for</span>(i=0; i&lt;blocks; i++) {</div>
<div class="line"> <a class="code" href="group__Pcpstream.html#gacfede4b1e9fa1ce0ccd7a55379ff6f15" title="Read bytes into the given buffer from the current stream.">ps_read</a>(pin, crypt, 8);</div>
<div class="line"> <a class="code" href="group__UTILs.html#gaad81054336208b62739f1e20091213a6" title="XOR an input buffer with another buffer.">_xorbuf</a>(key, crypt, 8);</div>
<div class="line"> <a class="code" href="group__Pcpstream.html#gab8e98ef81e802a242fbdb788b4387873" title="Write bytes from the given buffer into the current stream.">ps_write</a>(pclear, crypt, 8);</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a" title="Close the stream and frees allocated memory.">ps_close</a>(pin);</div>
<div class="line"> fclose(in);</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* now extract the buffer from the output stream */</span></div>
<div class="line"> <a class="code" href="struct__pcp__buffer.html" title="A flexible buffer object wich automatically resizes, if neccessary.">Buffer</a> *result = <a class="code" href="group__Pcpstream.html#ga64bc34dfbc1b3951c3d62e82a1ae8c34" title="Access the Buffer backend pointer.">ps_buffer</a>(pclear);</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* and verify if it&#39;s &quot;decrypted&quot; (re-use crypt) */</span></div>
<div class="line"> <span class="keywordflow">for</span>(i=0; i&lt;blocks; i++) {</div>
<div class="line"> <a class="code" href="group__Buffer.html#gaddf2e52378c6cd765b940617cdef2bd2" title="Read some chunk of data from the Buffer.">buffer_get_chunk</a>(result, crypt, 8);</div>
<div class="line"> <span class="keywordflow">if</span>(memcmp(crypt, clear, 8) != 0) {</div>
<div class="line"> fprintf(stderr, <span class="stringliteral">&quot;Oops, block %d doesn&#39;t match\n&quot;</span>, i);</div>
<div class="line"> <span class="keywordflow">goto</span> error;</div>
<div class="line"> }</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <a class="code" href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a" title="Close the stream and frees allocated memory.">ps_close</a>(pclear);</div>
<div class="line"></div>
<div class="line"> fprintf(stderr, <span class="stringliteral">&quot;done\n&quot;</span>);</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line"></div>
<div class="line"> error:</div>
<div class="line"> <a class="code" href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a" title="Close the stream and frees allocated memory.">ps_close</a>(pclear);</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line">}</div>
</div><!-- fragment --> <h2 class="groupheader">Typedef Documentation</h2>
<a class="anchor" id="gaec72241f86d5391d5cae7477c66cdd73"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">typedef struct <a class="el" href="struct__pcp__stream__t.html">_pcp_stream_t</a> <a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a></td>
</tr>
</table>
</div><div class="memdoc">
<p>The name used everywhere. </p>
<p>Definition at line <a class="el" href="pcpstream_8h_source.html#l00067">67</a> of file <a class="el" href="pcpstream_8h_source.html">pcpstream.h</a>.</p>
</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="ga64bc34dfbc1b3951c3d62e82a1ae8c34"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__Buffer.html#ga2460ea15a51a37433b5f2e1503667e8f">Buffer</a>* ps_buffer </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Access the Buffer backend pointer. </p>
<p>Use this function to access the underlying Buffer object of an output stream to access the contents written to it. Only usefull if the stream have been initialized with <a class="el" href="group__Pcpstream.html#ga13ec0245b579949e6d586e1817615d2e" title="Create a new output stream, backed with a buffer.">ps_new_outbuffer()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">stream</td><td>The stream object.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns a pointer to the Buffer object. </dd></dl>
</div>
</div>
<a class="anchor" id="ga4a68da22eca6e9bd854d54467a071d0a"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void ps_close </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Close the stream and frees allocated memory. </p>
<p>If the backend of the stream was a FILE stream, close it, unless it is stdin, stdout or stderr.</p>
<p>If the backend was a Buffer, clear and free it.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">stream</td><td>The stream to close. </td></tr>
</table>
</dd>
</dl>
</div>
</div>
<a class="anchor" id="gac845e4dc3677aeef5e4de343d3f8033d"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int ps_end </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Check if EOF have been reached. </p>
<p>This function can be used to check if there are no more bytes to read. This will happen if we reach EOF with a FILE backed stream or <a class="el" href="group__Buffer.html#ga914506665c6fac92ccb17f92cefd0914" title="Tell if there are no more bytes to read.">buffer_done()</a> with a Buffer backed stream.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">stream</td><td>The stream object.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns 1 if we reached EOF, 0 otherwise </dd></dl>
</div>
</div>
<a class="anchor" id="ga97b83164ecda8fd66897863ec7976890"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int ps_err </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Check if an error occurred during a read or write operation. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">stream</td><td>The stream object.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns 1 if there were any errors or 0 otherwise. Also check errno() and <a class="el" href="group__FATALS.html#ga0ea01da59af8a06c55258d78da6cb0cb" title="Prints error messages to STDERR, if there are some.">fatals_ifany()</a>. </dd></dl>
</div>
</div>
<a class="anchor" id="ga6733979d79704b2e3ce914662b0cebc8"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a>* ps_new_file </td>
<td>(</td>
<td class="paramtype">FILE *&#160;</td>
<td class="paramname"><em>backendfd</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Create a new stream, backed with an open file. </p>
<p>The stream used for in- or output.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">backendfd</td><td>An open FILE stream.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns a Pcpstream structure. </dd></dl>
</div>
</div>
<a class="anchor" id="ga1b50c92fdad290e59317af2404460662"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a>* ps_new_inbuffer </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Buffer.html#ga2460ea15a51a37433b5f2e1503667e8f">Buffer</a> *&#160;</td>
<td class="paramname"><em>b</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Create a new input stream, backed with filled a buffer. </p>
<p>This kind of stream can be used for reading only.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">b</td><td>A Buffer object filled with data.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns a Pcpstream structure. </dd></dl>
</div>
</div>
<a class="anchor" id="ga13ec0245b579949e6d586e1817615d2e"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a>* ps_new_outbuffer </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Create a new output stream, backed with a buffer. </p>
<p>The buffer used to write data to will be allocated and filled by the class. You can retrieve it later.</p>
<dl class="section return"><dt>Returns</dt><dd>Returns a Pcpstream structure. </dd></dl>
</div>
</div>
<a class="anchor" id="gafd50eb5e9c8ba399e133b6029eca8856"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">size_t ps_print </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">const char *&#160;</td>
<td class="paramname"><em>fmt</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">&#160;</td>
<td class="paramname"><em>...</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Write a formatted string to the stream. </p>
<p>Use an printf() style format string to print something out to a stream.</p>
<p>Sets err in case of an error. See <a class="el" href="group__Pcpstream.html#ga97b83164ecda8fd66897863ec7976890" title="Check if an error occurred during a read or write operation.">ps_err()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[out]</td><td class="paramname">stream</td><td>The input stream to read from.</td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">fmt</td><td>The printf() compatible format description.</td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">...</td><td>A variable number of arguments for the format string.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns the number of bytes written. in case of errors it returns 0. </dd></dl>
</div>
</div>
<a class="anchor" id="gacfede4b1e9fa1ce0ccd7a55379ff6f15"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">size_t ps_read </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>buf</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>readbytes</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Read bytes into the given buffer from the current stream. </p>
<p>This function reads 'readbytes' bytes from the stream into given buf. The buffer needs to be properly allocated by the caller in advance to have at least readbytes len.</p>
<p>Sets eof=1 if end of file or end of buffer has been reached.</p>
<p>Sets err=1 if an error occurred, fatals() maybe set, or errno.</p>
<p>See <a class="el" href="group__Pcpstream.html#gac845e4dc3677aeef5e4de343d3f8033d" title="Check if EOF have been reached.">ps_end()</a> and <a class="el" href="group__Pcpstream.html#ga97b83164ecda8fd66897863ec7976890" title="Check if an error occurred during a read or write operation.">ps_err()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">stream</td><td>The input stream to read from.</td></tr>
<tr><td class="paramdir">[out]</td><td class="paramname">buf</td><td>The buffer where to put read bytes.</td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">readbytes</td><td>The number of bytes to read.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns the bytes read, if there's nothing more to read, it returns 0. </dd></dl>
</div>
</div>
<a class="anchor" id="ga72812698d6b6aca964c7289be41eccf8"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">size_t ps_tell </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Tell the current read or write offset. </p>
<p>This function works like ftell() on a FILE stream or like Buffer-&gt;offset in the Buffer class.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">stream</td><td>The input stream to read from.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns the the number of bytes read/written so far. </dd></dl>
</div>
</div>
<a class="anchor" id="gab8e98ef81e802a242fbdb788b4387873"></a>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">size_t ps_write </td>
<td>(</td>
<td class="paramtype"><a class="el" href="group__Pcpstream.html#gaec72241f86d5391d5cae7477c66cdd73">Pcpstream</a> *&#160;</td>
<td class="paramname"><em>stream</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">void *&#160;</td>
<td class="paramname"><em>buf</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">size_t&#160;</td>
<td class="paramname"><em>writebytes</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Write bytes from the given buffer into the current stream. </p>
<p>This function writes 'writebytes' bytes from the given buf into the stream</p>
<p>Sets err in case of an error. See <a class="el" href="group__Pcpstream.html#ga97b83164ecda8fd66897863ec7976890" title="Check if an error occurred during a read or write operation.">ps_err()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[out]</td><td class="paramname">stream</td><td>The input stream to write to.</td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">buf</td><td>The buffer containing data to put into the stream.</td></tr>
<tr><td class="paramdir">[in]</td><td class="paramname">writebytes</td><td>The number of bytes to write.</td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns the number of bytes written. in case of errors it returns 0. </dd></dl>
</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Feb 20 2014 20:58:12 for libpcp by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.2
</small></address>
</body>
</html>