1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<refentry id="refbufdest">
<refmeta>
<refentrytitle>ne_buffer_destroy</refentrytitle>
<manvolnum>3</manvolnum>
</refmeta>
<refnamediv>
<refname id="ne_buffer_destroy">ne_buffer_destroy</refname>
<refname id="ne_buffer_finish">ne_buffer_finish</refname>
<refpurpose>destroy a buffer object</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis>
<funcsynopsisinfo>#include <ne_string.h></funcsynopsisinfo>
<funcprototype>
<funcdef>void <function>ne_buffer_destroy</function></funcdef>
<paramdef>ne_buffer *<parameter>buf</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>char *<function>ne_buffer_finish</function></funcdef>
<paramdef>ne_buffer *<parameter>buf</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para><function>ne_buffer_destroy</function> frees all memory
associated with the buffer. <function>ne_buffer_finish</function>
frees the buffer structure, but not the actual string stored in the
buffer, which is returned and must be <function>free</function>()d by
the caller.</para>
<para>Any use of the buffer object after calling either of these
functions gives undefined behaviour.</para>
</refsect1>
<refsect1>
<title>Return value</title>
<para><function>ne_buffer_finish</function> returns the
<function>malloc</function>-allocated string stored in the buffer.</para>
</refsect1>
<refsect1>
<title>Examples</title>
<para>An example use of <function>ne_buffer_finish</function>;
the <function>duplicate</function> function returns a string made up of
<parameter>n</parameter> copies of <parameter>str</parameter>:</para>
<programlisting>static char *duplicate(int n, const char *str)
{
ne_buffer *buf = ne_buffer_create();
while (n--) {
ne_buffer_zappend(buf, str);
}
return ne_buffer_finish(buf);
}</programlisting>
</refsect1>
<refsect1>
<title>See also</title>
<para><xref linkend="ne_buffer"/>, <xref linkend="ne_buffer_create"/>,
<xref linkend="ne_buffer_zappend"/></para>
</refsect1>
</refentry>
|