Added silc_buffer_purge.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 18 Jul 2006 13:11:47 +0000 (13:11 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 18 Jul 2006 13:11:47 +0000 (13:11 +0000)
lib/silcutil/silcbuffer.h

index 407ae219a3ad4d22731aa30f518eb0297bb2b6a2..644085025d6c5e7500bd19dd58eab0f2bfce216f 100644 (file)
@@ -121,7 +121,7 @@ typedef struct {
  *
  * NAME
  *
- *    #define silc_buffer_truelen(buffer)
+ *    SilcUInt32 silc_buffer_truelen(SilcBuffer sb)
  *
  * DESCRIPTION
  *
@@ -136,7 +136,7 @@ typedef struct {
  *
  * NAME
  *
- *    #define silc_buffer_len(buffer)
+ *    SilcUInt32 silc_buffer_len(SilcBuffer sb)
  *
  * DESCRIPTION
  *
@@ -151,7 +151,7 @@ typedef struct {
  *
  * NAME
  *
- *    #define silc_buffer_headlen(buffer)
+ *    SilcUInt32 silc_buffer_headlen(SilcBuffer sb)
  *
  * DESCRIPTION
  *
@@ -166,7 +166,7 @@ typedef struct {
  *
  * NAME
  *
- *    #define silc_buffer_taillen(buffer)
+ *    SilcUInt32 silc_buffer_taillen(SilcBuffer sb)
  *
  * DESCRIPTION
  *
@@ -192,6 +192,30 @@ typedef struct {
 #define silc_buffer_data(x) (x)->data
 /***/
 
+/****f* silcutil/SilcBufferAPI/silc_buffer_datalen
+ *
+ * NAME
+ *
+ *    #define silc_buffer_datalen ...
+ *
+ * DESCRIPTION
+ *
+ *    Macro that can be used in function argument list to give the data
+ *    pointer and the data length, instead of calling both silc_buffer_data
+ *    and silc_buffer_len separately.
+ *
+ * EXAMPLE
+ *
+ *    // Following are the same thing
+ *    silc_foo_function(foo, silc_buffer_datalen(buf));
+ *    silc_foo_function(foo, silc_buffer_data(buf), silc_buffer_len(buf));
+ *
+ * SOURCE
+ */
+#define silc_buffer_datalen(x) (x) ? silc_buffer_data(x) : NULL, \
+  (x) ? silc_buffer_len(x) : 0
+/***/
+
 /* Inline functions */
 
 /****f* silcutil/SilcBufferAPI/silc_buffer_alloc
@@ -286,6 +310,27 @@ unsigned char *silc_buffer_steal(SilcBuffer sb, SilcUInt32 *data_len)
   return buf;
 }
 
+/****f* silcutil/SilcBufferAPI/silc_buffer_purge
+ *
+ * SYNOPSIS
+ *
+ *    static inline
+ *    void silc_buffer_purge(SilcBuffer sb);
+ *
+ * DESCRIPTION
+ *
+ *    Same as silc_buffer_free but free's only the contents of the buffer
+ *    not the buffer itself.  The `sb' remains intact, data is freed.  Buffer
+ *    is ready for re-use after calling this function.
+ *
+ ***/
+
+static inline
+void silc_buffer_purge(SilcBuffer sb)
+{
+  silc_free(silc_buffer_steal(sb, NULL));
+}
+
 /****f* silcutil/SilcBufferAPI/silc_buffer_set
  *
  * SYNOPSIS