<trclass="memdesc:"><tdclass="mdescLeft"> </td><tdclass="mdescRight">An I/O wrapper object backed by a file or a buffer. <ahref="struct__pcp__stream__t.html#details">More...</a><br/></td></tr>
<trclass="memdesc:gaec72241f86d5391d5cae7477c66cdd73"><tdclass="mdescLeft"> </td><tdclass="mdescRight">The name used everywhere. <ahref="#gaec72241f86d5391d5cae7477c66cdd73"></a><br/></td></tr>
<trclass="memdesc:ga6733979d79704b2e3ce914662b0cebc8"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Create a new stream, backed with an open file. <ahref="#ga6733979d79704b2e3ce914662b0cebc8"></a><br/></td></tr>
<trclass="memdesc:ga1b50c92fdad290e59317af2404460662"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Create a new input stream, backed with filled a buffer. <ahref="#ga1b50c92fdad290e59317af2404460662"></a><br/></td></tr>
<trclass="memdesc:ga13ec0245b579949e6d586e1817615d2e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Create a new output stream, backed with a buffer. <ahref="#ga13ec0245b579949e6d586e1817615d2e"></a><br/></td></tr>
<trclass="memdesc:gacfede4b1e9fa1ce0ccd7a55379ff6f15"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Read bytes into the given buffer from the current stream. <ahref="#gacfede4b1e9fa1ce0ccd7a55379ff6f15"></a><br/></td></tr>
<trclass="memdesc:gab8e98ef81e802a242fbdb788b4387873"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Write bytes from the given buffer into the current stream. <ahref="#gab8e98ef81e802a242fbdb788b4387873"></a><br/></td></tr>
<trclass="memdesc:gafd50eb5e9c8ba399e133b6029eca8856"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Write a formatted string to the stream. <ahref="#gafd50eb5e9c8ba399e133b6029eca8856"></a><br/></td></tr>
<trclass="memdesc:ga72812698d6b6aca964c7289be41eccf8"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Tell the current read or write offset. <ahref="#ga72812698d6b6aca964c7289be41eccf8"></a><br/></td></tr>
<trclass="memdesc:ga4a68da22eca6e9bd854d54467a071d0a"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Close the stream and frees allocated memory. <ahref="#ga4a68da22eca6e9bd854d54467a071d0a"></a><br/></td></tr>
<trclass="memdesc:gac845e4dc3677aeef5e4de343d3f8033d"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Check if EOF have been reached. <ahref="#gac845e4dc3677aeef5e4de343d3f8033d"></a><br/></td></tr>
<trclass="memdesc:ga97b83164ecda8fd66897863ec7976890"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Check if an error occurred during a read or write operation. <ahref="#ga97b83164ecda8fd66897863ec7976890"></a><br/></td></tr>
<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>
<divclass="line"><aclass="code"href="struct__pcp__stream__t.html"title="An I/O wrapper object backed by a file or a buffer.">Pcpstream</a> *pout = <aclass="code"href="group__Pcpstream.html#ga6733979d79704b2e3ce914662b0cebc8"title="Create a new stream, backed with an open file.">ps_new_file</a>(out);</div>
<divclass="line"></div>
<divclass="line"><spanclass="comment">/* "encrypt" a couple of times into the file */</span></div>
<divclass="line"><aclass="code"href="group__UTILs.html#gaad81054336208b62739f1e20091213a6"title="XOR an input buffer with another buffer.">_xorbuf</a>(key, crypt, 8);</div>
<divclass="line"><aclass="code"href="group__Pcpstream.html#gab8e98ef81e802a242fbdb788b4387873"title="Write bytes from the given buffer into the current stream.">ps_write</a>(pout, crypt, 8);</div>
<divclass="line"> }</div>
<divclass="line"><aclass="code"href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a"title="Close the stream and frees allocated memory.">ps_close</a>(pout);</div>
<divclass="line"> fclose(out);</div>
<divclass="line"></div>
<divclass="line"><spanclass="comment">/* read it in again using an in and an out stream */</span></div>
<divclass="line"><aclass="code"href="struct__pcp__stream__t.html"title="An I/O wrapper object backed by a file or a buffer.">Pcpstream</a> *pin = <aclass="code"href="group__Pcpstream.html#ga6733979d79704b2e3ce914662b0cebc8"title="Create a new stream, backed with an open file.">ps_new_file</a>(in);</div>
<divclass="line"></div>
<divclass="line"><spanclass="comment">/* we'll use this stream to put the "decrypted" data in.</span></div>
<divclass="line"><spanclass="comment"> note, that this could be a file as well. */</span></div>
<divclass="line"><aclass="code"href="struct__pcp__stream__t.html"title="An I/O wrapper object backed by a file or a buffer.">Pcpstream</a> *pclear = <aclass="code"href="group__Pcpstream.html#ga13ec0245b579949e6d586e1817615d2e"title="Create a new output stream, backed with a buffer.">ps_new_outbuffer</a>();</div>
<divclass="line"></div>
<divclass="line"><spanclass="comment">/* read and "decrypt" */</span></div>
<divclass="line"><aclass="code"href="group__Pcpstream.html#gacfede4b1e9fa1ce0ccd7a55379ff6f15"title="Read bytes into the given buffer from the current stream.">ps_read</a>(pin, crypt, 8);</div>
<divclass="line"><aclass="code"href="group__UTILs.html#gaad81054336208b62739f1e20091213a6"title="XOR an input buffer with another buffer.">_xorbuf</a>(key, crypt, 8);</div>
<divclass="line"><aclass="code"href="group__Pcpstream.html#gab8e98ef81e802a242fbdb788b4387873"title="Write bytes from the given buffer into the current stream.">ps_write</a>(pclear, crypt, 8);</div>
<divclass="line"> }</div>
<divclass="line"><aclass="code"href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a"title="Close the stream and frees allocated memory.">ps_close</a>(pin);</div>
<divclass="line"> fclose(in);</div>
<divclass="line"></div>
<divclass="line"><spanclass="comment">/* now extract the buffer from the output stream */</span></div>
<divclass="line"><aclass="code"href="struct__pcp__buffer.html"title="A flexible buffer object wich automatically resizes, if neccessary.">Buffer</a> *result = <aclass="code"href="group__Pcpstream.html#ga64bc34dfbc1b3951c3d62e82a1ae8c34"title="Access the Buffer backend pointer.">ps_buffer</a>(pclear);</div>
<divclass="line"></div>
<divclass="line"><spanclass="comment">/* and verify if it's "decrypted" (re-use crypt) */</span></div>
<divclass="line"><aclass="code"href="group__Buffer.html#gaddf2e52378c6cd765b940617cdef2bd2"title="Read some chunk of data from the Buffer.">buffer_get_chunk</a>(result, crypt, 8);</div>
<divclass="line"><aclass="code"href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a"title="Close the stream and frees allocated memory.">ps_close</a>(pclear);</div>
<divclass="line"><aclass="code"href="group__Pcpstream.html#ga4a68da22eca6e9bd854d54467a071d0a"title="Close the stream and frees allocated memory.">ps_close</a>(pclear);</div>
<p>Definition at line <aclass="el"href="pcpstream_8h_source.html#l00067">67</a> of file <aclass="el"href="pcpstream_8h_source.html">pcpstream.h</a>.</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 <aclass="el"href="group__Pcpstream.html#ga13ec0245b579949e6d586e1817615d2e"title="Create a new output stream, backed with a buffer.">ps_new_outbuffer()</a>.</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 <aclass="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>
<dlclass="section return"><dt>Returns</dt><dd>Returns 1 if there were any errors or 0 otherwise. Also check errno() and <aclass="el"href="group__FATALS.html#ga0ea01da59af8a06c55258d78da6cb0cb"title="Prints error messages to STDERR, if there are some.">fatals_ifany()</a>. </dd></dl>
<p>Use an printf() style format string to print something out to a stream.</p>
<p>Sets err in case of an error. See <aclass="el"href="group__Pcpstream.html#ga97b83164ecda8fd66897863ec7976890"title="Check if an error occurred during a read or write operation.">ps_err()</a>.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">stream</td><td>The input stream to read from.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">fmt</td><td>The printf() compatible format description.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">...</td><td>A variable number of arguments for the format string.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns the number of bytes written. in case of errors it returns 0. </dd></dl>
<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 <aclass="el"href="group__Pcpstream.html#gac845e4dc3677aeef5e4de343d3f8033d"title="Check if EOF have been reached.">ps_end()</a> and <aclass="el"href="group__Pcpstream.html#ga97b83164ecda8fd66897863ec7976890"title="Check if an error occurred during a read or write operation.">ps_err()</a>.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">stream</td><td>The input stream to read from.</td></tr>
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">buf</td><td>The buffer where to put read bytes.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">readbytes</td><td>The number of bytes to read.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns the bytes read, if there's nothing more to read, it returns 0. </dd></dl>
<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 <aclass="el"href="group__Pcpstream.html#ga97b83164ecda8fd66897863ec7976890"title="Check if an error occurred during a read or write operation.">ps_err()</a>.</p>
<dlclass="params"><dt>Parameters</dt><dd>
<tableclass="params">
<tr><tdclass="paramdir">[out]</td><tdclass="paramname">stream</td><td>The input stream to write to.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">buf</td><td>The buffer containing data to put into the stream.</td></tr>
<tr><tdclass="paramdir">[in]</td><tdclass="paramname">writebytes</td><td>The number of bytes to write.</td></tr>
</table>
</dd>
</dl>
<dlclass="section return"><dt>Returns</dt><dd>Returns the number of bytes written. in case of errors it returns 0. </dd></dl>