+ sb->head = (unsigned char *)silc_malloc(len * sizeof(*sb->head));
+ if (silc_unlikely(!sb->head))
+ return NULL;
+
+ /* Set pointers to the new buffer */
+ sb->data = sb->head;
+ sb->tail = sb->head;
+ sb->end = sb->head + len;
+ }
+
+ return sb;
+}
+
+/****f* silcutil/SilcBufferAPI/silc_buffer_salloc
+ *
+ * SYNOPSIS
+ *
+ * static inline
+ * SilcBuffer silc_buffer_salloc(SilcStack stack, SilcUInt32 len);
+ *
+ * DESCRIPTION
+ *
+ * Allocates new SilcBuffer and returns it.
+ *
+ * This routine use SilcStack are memory source. If `stack' is NULL
+ * reverts back to normal allocating routine.
+ *
+ * Note that this call consumes the `stack'. The caller should push the
+ * stack before calling the function and pop it later.
+ *
+ ***/
+
+static inline
+SilcBuffer silc_buffer_salloc(SilcStack stack, SilcUInt32 len)
+{
+ SilcBuffer sb;
+
+ if (!stack)
+ return silc_buffer_alloc(len);
+
+ /* Allocate new SilcBuffer */
+ sb = (SilcBuffer)silc_scalloc(stack, 1, sizeof(*sb));
+ if (silc_unlikely(!sb))
+ return NULL;
+
+ if (silc_likely(len)) {
+ /* Allocate the actual data area */
+ sb->head = (unsigned char *)silc_smalloc(stack, len * sizeof(*sb->head));