<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>ldns documentation</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <div class="logo"> <img src="LogoInGradientBar2-y100.png"/> </div> <!-- Generated by Doxygen 1.7.4 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> </div> <div class="header"> <div class="summary"> <a href="#func-members">Functions</a> </div> <div class="headertitle"> <div class="title">buffer.c File Reference</div> </div> </div> <div class="contents"> <p><a href="buffer_8c_source.html">Go to the source code of this file.</a></p> <table class="memberdecls"> <tr><td colspan="2"><h2><a name="func-members"></a> Functions</h2></td></tr> <tr><td class="memItemLeft" align="right" valign="top"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#ac6d413e9a76bf7e7c2022f13e36b9900">ldns_buffer_new</a> (size_t capacity)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">creates a new buffer with the specified capacity. <a href="#ac6d413e9a76bf7e7c2022f13e36b9900"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#a7f33a4c147914739da73ccc4caa2bd7f">ldns_buffer_new_frm_data</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *buffer, void *data, size_t size)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">creates a buffer with the specified data. <a href="#a7f33a4c147914739da73ccc4caa2bd7f"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#a4e16fc0b5f97c6a3d91533c93f8f47c2">ldns_buffer_set_capacity</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *buffer, size_t capacity)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">changes the buffer's capacity. <a href="#a4e16fc0b5f97c6a3d91533c93f8f47c2"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#a8ba0bcb3201dae8d3e563ed201decc7c">ldns_buffer_reserve</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *buffer, size_t amount)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">ensures BUFFER can contain at least AMOUNT more bytes. <a href="#a8ba0bcb3201dae8d3e563ed201decc7c"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#ad0bd2ed28633df90c9c99974eaae4b5a">ldns_buffer_printf</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *buffer, const char *format,...)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">prints to the buffer, increasing the capacity if required using buffer_reserve(). <a href="#ad0bd2ed28633df90c9c99974eaae4b5a"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#a1615da957ad5a24a8b5cc1ba2f2b7f44">ldns_buffer_free</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *buffer)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">frees the buffer. <a href="#a1615da957ad5a24a8b5cc1ba2f2b7f44"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void * </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#aedc3ca34290f5faad3cca548bb7125ab">ldns_buffer_export</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *buffer)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Makes the buffer fixed and returns a pointer to the data. <a href="#aedc3ca34290f5faad3cca548bb7125ab"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#ac133a49136532ac36150f4378c45bd28">ldns_bgetc</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *buffer)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">returns the next character from a buffer. <a href="#ac133a49136532ac36150f4378c45bd28"></a><br/></td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="buffer_8c.html#a8aad3e9f377019a428cfd92b0ef6d534">ldns_buffer_copy</a> (<a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *result, <a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> *from)</td></tr> <tr><td class="mdescLeft"> </td><td class="mdescRight">Copy contents of the other buffer to this buffer. <a href="#a8aad3e9f377019a428cfd92b0ef6d534"></a><br/></td></tr> </table> <hr/><h2>Function Documentation</h2> <a class="anchor" id="ac6d413e9a76bf7e7c2022f13e36b9900"></a><!-- doxytag: member="buffer.c::ldns_buffer_new" ref="ac6d413e9a76bf7e7c2022f13e36b9900" args="(size_t capacity)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a>* ldns_buffer_new </td> <td>(</td> <td class="paramtype">size_t </td> <td class="paramname"><em>capacity</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>creates a new buffer with the specified capacity. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">capacity</td><td>the size (in bytes) to allocate for the buffer </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>the created buffer </dd></dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00016">16</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00059">ldns_struct_buffer::_capacity</a>, <a class="el" href="buffer_8h_source.html#l00062">ldns_struct_buffer::_data</a>, <a class="el" href="buffer_8h_source.html#l00065">ldns_struct_buffer::_fixed</a>, <a class="el" href="buffer_8h_source.html#l00056">ldns_struct_buffer::_limit</a>, <a class="el" href="buffer_8h_source.html#l00053">ldns_struct_buffer::_position</a>, <a class="el" href="buffer_8h_source.html#l00070">ldns_struct_buffer::_status</a>, <a class="el" href="util_8h_source.html#l00060">LDNS_FREE</a>, <a class="el" href="util_8h_source.html#l00049">LDNS_MALLOC</a>, <a class="el" href="error_8h_source.html#l00026">LDNS_STATUS_OK</a>, and <a class="el" href="util_8h_source.html#l00051">LDNS_XMALLOC</a>.</p> </div> </div> <a class="anchor" id="a7f33a4c147914739da73ccc4caa2bd7f"></a><!-- doxytag: member="buffer.c::ldns_buffer_new_frm_data" ref="a7f33a4c147914739da73ccc4caa2bd7f" args="(ldns_buffer *buffer, void *data, size_t size)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void ldns_buffer_new_frm_data </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>buffer</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">void * </td> <td class="paramname"><em>data</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">size_t </td> <td class="paramname"><em>size</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>creates a buffer with the specified data. </p> <p>The data IS copied and MEMORY allocations are done. The buffer is not fixed and can be resized using buffer_reserve().</p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">buffer</td><td>pointer to the buffer to put the data in </td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">data</td><td>the data to encapsulate in the buffer </td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">size</td><td>the size of the data </td></tr> </table> </dd> </dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00041">41</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00059">ldns_struct_buffer::_capacity</a>, <a class="el" href="buffer_8h_source.html#l00062">ldns_struct_buffer::_data</a>, <a class="el" href="buffer_8h_source.html#l00065">ldns_struct_buffer::_fixed</a>, <a class="el" href="buffer_8h_source.html#l00056">ldns_struct_buffer::_limit</a>, <a class="el" href="buffer_8h_source.html#l00053">ldns_struct_buffer::_position</a>, <a class="el" href="buffer_8h_source.html#l00070">ldns_struct_buffer::_status</a>, <a class="el" href="error_8h_source.html#l00034">LDNS_STATUS_MEM_ERR</a>, <a class="el" href="error_8h_source.html#l00026">LDNS_STATUS_OK</a>, and <a class="el" href="util_8h_source.html#l00051">LDNS_XMALLOC</a>.</p> </div> </div> <a class="anchor" id="a4e16fc0b5f97c6a3d91533c93f8f47c2"></a><!-- doxytag: member="buffer.c::ldns_buffer_set_capacity" ref="a4e16fc0b5f97c6a3d91533c93f8f47c2" args="(ldns_buffer *buffer, size_t capacity)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool ldns_buffer_set_capacity </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>buffer</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">size_t </td> <td class="paramname"><em>capacity</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>changes the buffer's capacity. </p> <p>The data is reallocated so any pointers to the data may become invalid. The buffer's limit is set to the buffer's new capacity. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">buffer</td><td>the buffer </td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">capacity</td><td>the capacity to use </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>whether this failed or succeeded </dd></dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00060">60</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00059">ldns_struct_buffer::_capacity</a>, <a class="el" href="buffer_8h_source.html#l00062">ldns_struct_buffer::_data</a>, <a class="el" href="buffer_8h_source.html#l00056">ldns_struct_buffer::_limit</a>, <a class="el" href="buffer_8h_source.html#l00053">ldns_struct_buffer::_position</a>, <a class="el" href="buffer_8h_source.html#l00070">ldns_struct_buffer::_status</a>, <a class="el" href="error_8h_source.html#l00034">LDNS_STATUS_MEM_ERR</a>, and <a class="el" href="util_8h_source.html#l00057">LDNS_XREALLOC</a>.</p> </div> </div> <a class="anchor" id="a8ba0bcb3201dae8d3e563ed201decc7c"></a><!-- doxytag: member="buffer.c::ldns_buffer_reserve" ref="a8ba0bcb3201dae8d3e563ed201decc7c" args="(ldns_buffer *buffer, size_t amount)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">bool ldns_buffer_reserve </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>buffer</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">size_t </td> <td class="paramname"><em>amount</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>ensures BUFFER can contain at least AMOUNT more bytes. </p> <p>The buffer's capacity is increased if necessary using buffer_set_capacity().</p> <p>The buffer's limit is always set to the (possibly increased) capacity. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">buffer</td><td>the buffer </td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">amount</td><td>amount to use </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>whether this failed or succeeded </dd></dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00079">79</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00059">ldns_struct_buffer::_capacity</a>, <a class="el" href="buffer_8h_source.html#l00065">ldns_struct_buffer::_fixed</a>, <a class="el" href="buffer_8h_source.html#l00056">ldns_struct_buffer::_limit</a>, <a class="el" href="buffer_8h_source.html#l00053">ldns_struct_buffer::_position</a>, <a class="el" href="buffer_8h_source.html#l00070">ldns_struct_buffer::_status</a>, <a class="el" href="buffer_8c_source.html#l00060">ldns_buffer_set_capacity()</a>, and <a class="el" href="error_8h_source.html#l00034">LDNS_STATUS_MEM_ERR</a>.</p> </div> </div> <a class="anchor" id="ad0bd2ed28633df90c9c99974eaae4b5a"></a><!-- doxytag: member="buffer.c::ldns_buffer_printf" ref="ad0bd2ed28633df90c9c99974eaae4b5a" args="(ldns_buffer *buffer, const char *format,...)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int ldns_buffer_printf </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>buffer</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">const char * </td> <td class="paramname"><em>format</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"> </td> <td class="paramname"><em>...</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>prints to the buffer, increasing the capacity if required using buffer_reserve(). </p> <p>The buffer's position is set to the terminating '\0' Returns the number of characters written (not including the terminating '\0') or -1 on failure. </p> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00099">99</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00059">ldns_struct_buffer::_capacity</a>, <a class="el" href="buffer_8h_source.html#l00056">ldns_struct_buffer::_limit</a>, <a class="el" href="buffer_8h_source.html#l00053">ldns_struct_buffer::_position</a>, <a class="el" href="buffer_8h_source.html#l00070">ldns_struct_buffer::_status</a>, <a class="el" href="buffer_8c_source.html#l00079">ldns_buffer_reserve()</a>, <a class="el" href="error_8h_source.html#l00035">LDNS_STATUS_INTERNAL_ERR</a>, <a class="el" href="error_8h_source.html#l00034">LDNS_STATUS_MEM_ERR</a>, and <a class="el" href="config_8h.html#a90f649eb9607cf5003051e74c60b39a6">vsnprintf()</a>.</p> </div> </div> <a class="anchor" id="a1615da957ad5a24a8b5cc1ba2f2b7f44"></a><!-- doxytag: member="buffer.c::ldns_buffer_free" ref="a1615da957ad5a24a8b5cc1ba2f2b7f44" args="(ldns_buffer *buffer)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void ldns_buffer_free </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>buffer</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>frees the buffer. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">*buffer</td><td>the buffer to be freed </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>void </dd></dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00137">137</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00062">ldns_struct_buffer::_data</a>, and <a class="el" href="util_8h_source.html#l00060">LDNS_FREE</a>.</p> </div> </div> <a class="anchor" id="aedc3ca34290f5faad3cca548bb7125ab"></a><!-- doxytag: member="buffer.c::ldns_buffer_export" ref="aedc3ca34290f5faad3cca548bb7125ab" args="(ldns_buffer *buffer)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void* ldns_buffer_export </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>buffer</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>Makes the buffer fixed and returns a pointer to the data. </p> <p>The caller is responsible for free'ing the result. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">*buffer</td><td>the buffer to be exported </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>void </dd></dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00149">149</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00062">ldns_struct_buffer::_data</a>, and <a class="el" href="buffer_8h_source.html#l00065">ldns_struct_buffer::_fixed</a>.</p> </div> </div> <a class="anchor" id="ac133a49136532ac36150f4378c45bd28"></a><!-- doxytag: member="buffer.c::ldns_bgetc" ref="ac133a49136532ac36150f4378c45bd28" args="(ldns_buffer *buffer)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">int ldns_bgetc </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>buffer</em></td><td>)</td> <td></td> </tr> </table> </div> <div class="memdoc"> <p>returns the next character from a buffer. </p> <p>Advances the position pointer with 1. When end of buffer is reached returns EOF. This is the buffer's equivalent for getc(). </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[in]</td><td class="paramname">*buffer</td><td>buffer to read from </td></tr> </table> </dd> </dl> <dl class="return"><dt><b>Returns:</b></dt><dd>EOF on failure otherwise return the character </dd></dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00156">156</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> <p>References <a class="el" href="buffer_8h_source.html#l00053">ldns_struct_buffer::_position</a>.</p> </div> </div> <a class="anchor" id="a8aad3e9f377019a428cfd92b0ef6d534"></a><!-- doxytag: member="buffer.c::ldns_buffer_copy" ref="a8aad3e9f377019a428cfd92b0ef6d534" args="(ldns_buffer *result, ldns_buffer *from)" --> <div class="memitem"> <div class="memproto"> <table class="memname"> <tr> <td class="memname">void ldns_buffer_copy </td> <td>(</td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>result</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"><a class="el" href="structldns__struct__buffer.html">ldns_buffer</a> * </td> <td class="paramname"><em>from</em> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td> </tr> </table> </div> <div class="memdoc"> <p>Copy contents of the other buffer to this buffer. </p> <p>Silently truncated if this buffer is too small. </p> <dl><dt><b>Parameters:</b></dt><dd> <table class="params"> <tr><td class="paramdir">[out]</td><td class="paramname">*result</td><td>resulting buffer which is copied to. </td></tr> <tr><td class="paramdir">[in]</td><td class="paramname">*from</td><td>what to copy to result. </td></tr> </table> </dd> </dl> <p>Definition at line <a class="el" href="buffer_8c_source.html#l00167">167</a> of file <a class="el" href="buffer_8c_source.html">buffer.c</a>.</p> </div> </div> </div> <hr class="footer"/><address class="footer"><small>Generated on Wed Jan 11 2012 for ldns by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address> </body> </html>