<!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 id="nav-path" class="navpath"> <ul> <li class="navelem"><a class="el" href="dir_7a7a565456b510ac01baf8655647d8a2.html">ldns</a> </li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <div class="title">buffer.h</div> </div> </div> <div class="contents"> <a href="buffer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * buffer.h -- generic memory buffer.</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * Copyright (c) 2005-2008, NLnet Labs. All rights reserved.</span> <a name="l00005"></a>00005 <span class="comment"> *</span> <a name="l00006"></a>00006 <span class="comment"> * See LICENSE for the license.</span> <a name="l00007"></a>00007 <span class="comment"> *</span> <a name="l00008"></a>00008 <span class="comment"> *</span> <a name="l00009"></a>00009 <span class="comment"> * The buffer module implements a generic buffer. The API is based on</span> <a name="l00010"></a>00010 <span class="comment"> * the java.nio.Buffer interface.</span> <a name="l00011"></a>00011 <span class="comment"> */</span> <a name="l00012"></a>00012 <a name="l00013"></a>00013 <span class="preprocessor">#ifndef LDNS_BUFFER_H</span> <a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define LDNS_BUFFER_H</span> <a name="l00015"></a>00015 <span class="preprocessor"></span> <a name="l00016"></a>00016 <span class="preprocessor">#include <assert.h></span> <a name="l00017"></a>00017 <span class="preprocessor">#include <stdarg.h></span> <a name="l00018"></a>00018 <span class="preprocessor">#include <string.h></span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="preprocessor">#include <<a class="code" href="error_8h.html" title="Defines error numbers and functions to translate those to a readable string.">ldns/error.h</a>></span> <a name="l00021"></a>00021 <span class="preprocessor">#include <<a class="code" href="common_8h.html" title="Common definitions for LDNS.">ldns/common.h</a>></span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="preprocessor">#include "<a class="code" href="util_8h.html">ldns/util.h</a>"</span> <a name="l00024"></a>00024 <a name="l00025"></a>00025 <span class="preprocessor">#ifdef __cplusplus</span> <a name="l00026"></a>00026 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">"C"</span> { <a name="l00027"></a>00027 <span class="preprocessor">#endif</span> <a name="l00028"></a>00028 <span class="preprocessor"></span> <a name="l00033"></a><a class="code" href="buffer_8h.html#af725b95a81365884b13c31a2f5d4c107">00033</a> <span class="preprocessor">#define LDNS_MIN_BUFLEN 512</span> <a name="l00034"></a>00034 <span class="preprocessor"></span> <a name="l00050"></a><a class="code" href="structldns__struct__buffer.html">00050</a> <span class="keyword">struct </span><a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_struct_buffer</a> <a name="l00051"></a>00051 { <a name="l00053"></a><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb">00053</a> <span class="keywordtype">size_t</span> <a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>; <a name="l00054"></a>00054 <a name="l00056"></a><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5">00056</a> <span class="keywordtype">size_t</span> <a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>; <a name="l00057"></a>00057 <a name="l00059"></a><a class="code" href="structldns__struct__buffer.html#a0e2253a51f3cfb0a8c8b23d288861326">00059</a> <span class="keywordtype">size_t</span> <a class="code" href="structldns__struct__buffer.html#a0e2253a51f3cfb0a8c8b23d288861326" title="The amount of data the buffer can contain.">_capacity</a>; <a name="l00060"></a>00060 <a name="l00062"></a><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7">00062</a> uint8_t *<a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a>; <a name="l00063"></a>00063 <a name="l00065"></a><a class="code" href="structldns__struct__buffer.html#a67628b76dc8f1e174fa5667e2543bf4a">00065</a> <span class="keywordtype">unsigned</span> <a class="code" href="structldns__struct__buffer.html#a67628b76dc8f1e174fa5667e2543bf4a" title="If the buffer is fixed it cannot be resized.">_fixed</a> : 1; <a name="l00066"></a>00066 <a name="l00070"></a><a class="code" href="structldns__struct__buffer.html#ad19d973074968b399a74f32b6402c05c">00070</a> <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a class="code" href="structldns__struct__buffer.html#ad19d973074968b399a74f32b6402c05c" title="The current state of the buffer.">_status</a>; <a name="l00071"></a>00071 }; <a name="l00072"></a><a class="code" href="buffer_8h.html#a18a66fc6cf2cca871542c747e3c95385">00072</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_struct_buffer</a> <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a>; <a name="l00073"></a>00073 <a name="l00074"></a>00074 <a name="l00075"></a>00075 <span class="preprocessor">#ifdef NDEBUG</span> <a name="l00076"></a>00076 <span class="preprocessor"></span><a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00077"></a>00077 ldns_buffer_invariant(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *<a class="code" href="common_8h.html#ade436d89899edbffbc53514d440d28b9">ATTR_UNUSED</a>(buffer)) <a name="l00078"></a>00078 { <a name="l00079"></a>00079 } <a name="l00080"></a>00080 <span class="preprocessor">#else</span> <a name="l00081"></a>00081 <span class="preprocessor"></span><a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00082"></a>00082 ldns_buffer_invariant(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00083"></a>00083 { <a name="l00084"></a>00084 assert(buffer != NULL); <a name="l00085"></a>00085 assert(buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> <= buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>); <a name="l00086"></a>00086 assert(buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a> <= buffer-><a class="code" href="structldns__struct__buffer.html#a0e2253a51f3cfb0a8c8b23d288861326" title="The amount of data the buffer can contain.">_capacity</a>); <a name="l00087"></a>00087 assert(buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> != NULL); <a name="l00088"></a>00088 } <a name="l00089"></a>00089 <span class="preprocessor">#endif</span> <a name="l00090"></a>00090 <span class="preprocessor"></span> <a name="l00097"></a>00097 <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *<a class="code" href="buffer_8c.html#ac6d413e9a76bf7e7c2022f13e36b9900" title="creates a new buffer with the specified capacity.">ldns_buffer_new</a>(<span class="keywordtype">size_t</span> capacity); <a name="l00098"></a>00098 <a name="l00108"></a>00108 <span class="keywordtype">void</span> <a class="code" href="buffer_8c.html#a7f33a4c147914739da73ccc4caa2bd7f" title="creates a buffer with the specified data.">ldns_buffer_new_frm_data</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> size); <a name="l00109"></a>00109 <a name="l00115"></a>00115 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> ldns_buffer_clear(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00116"></a>00116 { <a name="l00117"></a>00117 ldns_buffer_invariant(buffer); <a name="l00118"></a>00118 <a name="l00119"></a>00119 <span class="comment">/* reset status here? */</span> <a name="l00120"></a>00120 <a name="l00121"></a>00121 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> = 0; <a name="l00122"></a>00122 buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a> = buffer-><a class="code" href="structldns__struct__buffer.html#a0e2253a51f3cfb0a8c8b23d288861326" title="The amount of data the buffer can contain.">_capacity</a>; <a name="l00123"></a>00123 } <a name="l00124"></a>00124 <a name="l00133"></a>00133 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> ldns_buffer_flip(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00134"></a>00134 { <a name="l00135"></a>00135 ldns_buffer_invariant(buffer); <a name="l00136"></a>00136 <a name="l00137"></a>00137 buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a> = buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>; <a name="l00138"></a>00138 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> = 0; <a name="l00139"></a>00139 } <a name="l00140"></a>00140 <a name="l00146"></a>00146 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> ldns_buffer_rewind(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00147"></a>00147 { <a name="l00148"></a>00148 ldns_buffer_invariant(buffer); <a name="l00149"></a>00149 <a name="l00150"></a>00150 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> = 0; <a name="l00151"></a>00151 } <a name="l00152"></a>00152 <a name="l00158"></a>00158 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">size_t</span> <a name="l00159"></a>00159 ldns_buffer_position(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00160"></a>00160 { <a name="l00161"></a>00161 <span class="keywordflow">return</span> buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>; <a name="l00162"></a>00162 } <a name="l00163"></a>00163 <a name="l00170"></a>00170 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00171"></a>00171 ldns_buffer_set_position(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> mark) <a name="l00172"></a>00172 { <a name="l00173"></a>00173 assert(mark <= buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>); <a name="l00174"></a>00174 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> = mark; <a name="l00175"></a>00175 } <a name="l00176"></a>00176 <a name="l00184"></a>00184 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00185"></a>00185 ldns_buffer_skip(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, ssize_t count) <a name="l00186"></a>00186 { <a name="l00187"></a>00187 assert(buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> + count <= buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>); <a name="l00188"></a>00188 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += count; <a name="l00189"></a>00189 } <a name="l00190"></a>00190 <a name="l00196"></a>00196 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">size_t</span> <a name="l00197"></a>00197 ldns_buffer_limit(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00198"></a>00198 { <a name="l00199"></a>00199 <span class="keywordflow">return</span> buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>; <a name="l00200"></a>00200 } <a name="l00201"></a>00201 <a name="l00208"></a>00208 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00209"></a>00209 ldns_buffer_set_limit(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> limit) <a name="l00210"></a>00210 { <a name="l00211"></a>00211 assert(limit <= buffer-><a class="code" href="structldns__struct__buffer.html#a0e2253a51f3cfb0a8c8b23d288861326" title="The amount of data the buffer can contain.">_capacity</a>); <a name="l00212"></a>00212 buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a> = limit; <a name="l00213"></a>00213 <span class="keywordflow">if</span> (buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> > buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>) <a name="l00214"></a>00214 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> = buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>; <a name="l00215"></a>00215 } <a name="l00216"></a>00216 <a name="l00222"></a>00222 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">size_t</span> <a name="l00223"></a>00223 ldns_buffer_capacity(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00224"></a>00224 { <a name="l00225"></a>00225 <span class="keywordflow">return</span> buffer-><a class="code" href="structldns__struct__buffer.html#a0e2253a51f3cfb0a8c8b23d288861326" title="The amount of data the buffer can contain.">_capacity</a>; <a name="l00226"></a>00226 } <a name="l00227"></a>00227 <a name="l00236"></a>00236 <span class="keywordtype">bool</span> <a class="code" href="buffer_8c.html#a4e16fc0b5f97c6a3d91533c93f8f47c2" title="changes the buffer's capacity.">ldns_buffer_set_capacity</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> capacity); <a name="l00237"></a>00237 <a name="l00248"></a>00248 <span class="keywordtype">bool</span> <a class="code" href="buffer_8c.html#a8ba0bcb3201dae8d3e563ed201decc7c" title="ensures BUFFER can contain at least AMOUNT more bytes.">ldns_buffer_reserve</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> amount); <a name="l00249"></a>00249 <a name="l00256"></a>00256 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint8_t * <a name="l00257"></a>00257 ldns_buffer_at(<span class="keyword">const</span> <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at) <a name="l00258"></a>00258 { <a name="l00259"></a>00259 assert(at <= buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>); <a name="l00260"></a>00260 <span class="keywordflow">return</span> buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> + at; <a name="l00261"></a>00261 } <a name="l00262"></a>00262 <a name="l00269"></a>00269 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint8_t * <a name="l00270"></a>00270 ldns_buffer_begin(<span class="keyword">const</span> <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00271"></a>00271 { <a name="l00272"></a>00272 <span class="keywordflow">return</span> ldns_buffer_at(buffer, 0); <a name="l00273"></a>00273 } <a name="l00274"></a>00274 <a name="l00281"></a>00281 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint8_t * <a name="l00282"></a>00282 ldns_buffer_end(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00283"></a>00283 { <a name="l00284"></a>00284 <span class="keywordflow">return</span> ldns_buffer_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>); <a name="l00285"></a>00285 } <a name="l00286"></a>00286 <a name="l00292"></a>00292 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint8_t * <a name="l00293"></a>00293 ldns_buffer_current(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00294"></a>00294 { <a name="l00295"></a>00295 <span class="keywordflow">return</span> ldns_buffer_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>); <a name="l00296"></a>00296 } <a name="l00297"></a>00297 <a name="l00305"></a>00305 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">size_t</span> <a name="l00306"></a>00306 ldns_buffer_remaining_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at) <a name="l00307"></a>00307 { <a name="l00308"></a>00308 ldns_buffer_invariant(buffer); <a name="l00309"></a>00309 assert(at <= buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a>); <a name="l00310"></a>00310 <span class="keywordflow">return</span> buffer-><a class="code" href="structldns__struct__buffer.html#af6eb085e24852584020b4bc5459d4cf5" title="The read/write limit.">_limit</a> - at; <a name="l00311"></a>00311 } <a name="l00312"></a>00312 <a name="l00319"></a>00319 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">size_t</span> <a name="l00320"></a>00320 ldns_buffer_remaining(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00321"></a>00321 { <a name="l00322"></a>00322 <span class="keywordflow">return</span> ldns_buffer_remaining_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>); <a name="l00323"></a>00323 } <a name="l00324"></a>00324 <a name="l00334"></a>00334 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">int</span> <a name="l00335"></a>00335 ldns_buffer_available_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at, <span class="keywordtype">size_t</span> count) <a name="l00336"></a>00336 { <a name="l00337"></a>00337 <span class="keywordflow">return</span> count <= ldns_buffer_remaining_at(buffer, at); <a name="l00338"></a>00338 } <a name="l00339"></a>00339 <a name="l00346"></a>00346 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">int</span> <a name="l00347"></a>00347 ldns_buffer_available(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> count) <a name="l00348"></a>00348 { <a name="l00349"></a>00349 <span class="keywordflow">return</span> ldns_buffer_available_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>, count); <a name="l00350"></a>00350 } <a name="l00351"></a>00351 <a name="l00359"></a>00359 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00360"></a>00360 ldns_buffer_write_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at, <span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> count) <a name="l00361"></a>00361 { <a name="l00362"></a>00362 assert(ldns_buffer_available_at(buffer, at, count)); <a name="l00363"></a>00363 memcpy(buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> + at, data, count); <a name="l00364"></a>00364 } <a name="l00365"></a>00365 <a name="l00372"></a>00372 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00373"></a>00373 ldns_buffer_write(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keyword">const</span> <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> count) <a name="l00374"></a>00374 { <a name="l00375"></a>00375 ldns_buffer_write_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>, data, count); <a name="l00376"></a>00376 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += count; <a name="l00377"></a>00377 } <a name="l00378"></a>00378 <a name="l00385"></a>00385 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00386"></a>00386 ldns_buffer_write_string_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at, <span class="keyword">const</span> <span class="keywordtype">char</span> *str) <a name="l00387"></a>00387 { <a name="l00388"></a>00388 ldns_buffer_write_at(buffer, at, str, strlen(str)); <a name="l00389"></a>00389 } <a name="l00390"></a>00390 <a name="l00396"></a>00396 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00397"></a>00397 ldns_buffer_write_string(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keyword">const</span> <span class="keywordtype">char</span> *str) <a name="l00398"></a>00398 { <a name="l00399"></a>00399 ldns_buffer_write(buffer, str, strlen(str)); <a name="l00400"></a>00400 } <a name="l00401"></a>00401 <a name="l00408"></a>00408 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00409"></a>00409 ldns_buffer_write_u8_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at, uint8_t data) <a name="l00410"></a>00410 { <a name="l00411"></a>00411 assert(ldns_buffer_available_at(buffer, at, <span class="keyword">sizeof</span>(data))); <a name="l00412"></a>00412 buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a>[at] = data; <a name="l00413"></a>00413 } <a name="l00414"></a>00414 <a name="l00420"></a>00420 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00421"></a>00421 ldns_buffer_write_u8(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, uint8_t data) <a name="l00422"></a>00422 { <a name="l00423"></a>00423 ldns_buffer_write_u8_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>, data); <a name="l00424"></a>00424 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += <span class="keyword">sizeof</span>(data); <a name="l00425"></a>00425 } <a name="l00426"></a>00426 <a name="l00433"></a>00433 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00434"></a>00434 ldns_buffer_write_u16_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at, uint16_t data) <a name="l00435"></a>00435 { <a name="l00436"></a>00436 assert(ldns_buffer_available_at(buffer, at, <span class="keyword">sizeof</span>(data))); <a name="l00437"></a>00437 ldns_write_uint16(buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> + at, data); <a name="l00438"></a>00438 } <a name="l00439"></a>00439 <a name="l00445"></a>00445 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00446"></a>00446 ldns_buffer_write_u16(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, uint16_t data) <a name="l00447"></a>00447 { <a name="l00448"></a>00448 ldns_buffer_write_u16_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>, data); <a name="l00449"></a>00449 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += <span class="keyword">sizeof</span>(data); <a name="l00450"></a>00450 } <a name="l00451"></a>00451 <a name="l00458"></a>00458 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00459"></a>00459 ldns_buffer_write_u32_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at, uint32_t data) <a name="l00460"></a>00460 { <a name="l00461"></a>00461 assert(ldns_buffer_available_at(buffer, at, <span class="keyword">sizeof</span>(data))); <a name="l00462"></a>00462 ldns_write_uint32(buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> + at, data); <a name="l00463"></a>00463 } <a name="l00464"></a>00464 <a name="l00470"></a>00470 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00471"></a>00471 ldns_buffer_write_u32(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, uint32_t data) <a name="l00472"></a>00472 { <a name="l00473"></a>00473 ldns_buffer_write_u32_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>, data); <a name="l00474"></a>00474 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += <span class="keyword">sizeof</span>(data); <a name="l00475"></a>00475 } <a name="l00476"></a>00476 <a name="l00484"></a>00484 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00485"></a>00485 ldns_buffer_read_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> count) <a name="l00486"></a>00486 { <a name="l00487"></a>00487 assert(ldns_buffer_available_at(buffer, at, count)); <a name="l00488"></a>00488 memcpy(data, buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> + at, count); <a name="l00489"></a>00489 } <a name="l00490"></a>00490 <a name="l00497"></a>00497 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">void</span> <a name="l00498"></a>00498 ldns_buffer_read(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">void</span> *data, <span class="keywordtype">size_t</span> count) <a name="l00499"></a>00499 { <a name="l00500"></a>00500 ldns_buffer_read_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>, data, count); <a name="l00501"></a>00501 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += count; <a name="l00502"></a>00502 } <a name="l00503"></a>00503 <a name="l00510"></a>00510 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint8_t <a name="l00511"></a>00511 ldns_buffer_read_u8_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at) <a name="l00512"></a>00512 { <a name="l00513"></a>00513 assert(ldns_buffer_available_at(buffer, at, <span class="keyword">sizeof</span>(uint8_t))); <a name="l00514"></a>00514 <span class="keywordflow">return</span> buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a>[at]; <a name="l00515"></a>00515 } <a name="l00516"></a>00516 <a name="l00522"></a>00522 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint8_t <a name="l00523"></a>00523 ldns_buffer_read_u8(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00524"></a>00524 { <a name="l00525"></a>00525 uint8_t result = ldns_buffer_read_u8_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>); <a name="l00526"></a>00526 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += <span class="keyword">sizeof</span>(uint8_t); <a name="l00527"></a>00527 <span class="keywordflow">return</span> result; <a name="l00528"></a>00528 } <a name="l00529"></a>00529 <a name="l00536"></a>00536 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint16_t <a name="l00537"></a>00537 ldns_buffer_read_u16_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at) <a name="l00538"></a>00538 { <a name="l00539"></a>00539 assert(ldns_buffer_available_at(buffer, at, <span class="keyword">sizeof</span>(uint16_t))); <a name="l00540"></a>00540 <span class="keywordflow">return</span> ldns_read_uint16(buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> + at); <a name="l00541"></a>00541 } <a name="l00542"></a>00542 <a name="l00548"></a>00548 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint16_t <a name="l00549"></a>00549 ldns_buffer_read_u16(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00550"></a>00550 { <a name="l00551"></a>00551 uint16_t result = ldns_buffer_read_u16_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>); <a name="l00552"></a>00552 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += <span class="keyword">sizeof</span>(uint16_t); <a name="l00553"></a>00553 <span class="keywordflow">return</span> result; <a name="l00554"></a>00554 } <a name="l00555"></a>00555 <a name="l00562"></a>00562 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint32_t <a name="l00563"></a>00563 ldns_buffer_read_u32_at(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keywordtype">size_t</span> at) <a name="l00564"></a>00564 { <a name="l00565"></a>00565 assert(ldns_buffer_available_at(buffer, at, <span class="keyword">sizeof</span>(uint32_t))); <a name="l00566"></a>00566 <span class="keywordflow">return</span> ldns_read_uint32(buffer-><a class="code" href="structldns__struct__buffer.html#ae4e2615ee600913816488ec2945b85c7" title="The data contained in the buffer.">_data</a> + at); <a name="l00567"></a>00567 } <a name="l00568"></a>00568 <a name="l00574"></a>00574 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> uint32_t <a name="l00575"></a>00575 ldns_buffer_read_u32(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00576"></a>00576 { <a name="l00577"></a>00577 uint32_t result = ldns_buffer_read_u32_at(buffer, buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a>); <a name="l00578"></a>00578 buffer-><a class="code" href="structldns__struct__buffer.html#ac62e89526e2292f430cb815620ee2ebb" title="The current position used for reading/writing.">_position</a> += <span class="keyword">sizeof</span>(uint32_t); <a name="l00579"></a>00579 <span class="keywordflow">return</span> result; <a name="l00580"></a>00580 } <a name="l00581"></a>00581 <a name="l00587"></a>00587 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00588"></a>00588 ldns_buffer_status(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00589"></a>00589 { <a name="l00590"></a>00590 <span class="keywordflow">return</span> buffer-><a class="code" href="structldns__struct__buffer.html#ad19d973074968b399a74f32b6402c05c" title="The current state of the buffer.">_status</a>; <a name="l00591"></a>00591 } <a name="l00592"></a>00592 <a name="l00598"></a>00598 <a class="code" href="util_8h.html#a2eb6f9e0395b47b8d5e3eeae4fe0c116" title="splint static inline workaround">INLINE</a> <span class="keywordtype">bool</span> <a name="l00599"></a>00599 ldns_buffer_status_ok(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00600"></a>00600 { <a name="l00601"></a>00601 <span class="keywordflow">if</span> (buffer) { <a name="l00602"></a>00602 <span class="keywordflow">return</span> ldns_buffer_status(buffer) == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00603"></a>00603 } <span class="keywordflow">else</span> { <a name="l00604"></a>00604 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00605"></a>00605 } <a name="l00606"></a>00606 } <a name="l00607"></a>00607 <a name="l00614"></a>00614 <span class="keywordtype">int</span> <a class="code" href="buffer_8c.html#ad0bd2ed28633df90c9c99974eaae4b5a" title="prints to the buffer, increasing the capacity if required using buffer_reserve().">ldns_buffer_printf</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer, <span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...); <a name="l00615"></a>00615 <span class="comment">/* ATTR_FORMAT(printf, 2, 3);*/</span> <a name="l00616"></a>00616 <a name="l00622"></a>00622 <span class="keywordtype">void</span> <a class="code" href="buffer_8c.html#a1615da957ad5a24a8b5cc1ba2f2b7f44" title="frees the buffer.">ldns_buffer_free</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer); <a name="l00623"></a>00623 <a name="l00630"></a>00630 <span class="keywordtype">void</span> *<a class="code" href="buffer_8c.html#aedc3ca34290f5faad3cca548bb7125ab" title="Makes the buffer fixed and returns a pointer to the data.">ldns_buffer_export</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer); <a name="l00631"></a>00631 <a name="l00638"></a>00638 <span class="keywordtype">void</span> <a class="code" href="buffer_8c.html#a8aad3e9f377019a428cfd92b0ef6d534" title="Copy contents of the other buffer to this buffer.">ldns_buffer_copy</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a>* result, <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a>* from); <a name="l00639"></a>00639 <a name="l00640"></a>00640 <span class="preprocessor">#ifdef __cplusplus</span> <a name="l00641"></a>00641 <span class="preprocessor"></span>} <a name="l00642"></a>00642 <span class="preprocessor">#endif</span> <a name="l00643"></a>00643 <span class="preprocessor"></span> <a name="l00644"></a>00644 <span class="preprocessor">#endif </span><span class="comment">/* LDNS_BUFFER_H */</span> </pre></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>