+ if (silc_unlikely(!h))
+ return NULL;
+ sb->head = h;
+ sb->data = sb->head + hlen;
+ sb->tail = sb->data + dlen;
+ sb->end = sb->head + newsize;
+
+ return sb;
+}
+
+/****f* silcutil/SilcBufferAPI/silc_buffer_srealloc
+ *
+ * SYNOPSIS
+ *
+ * static inline
+ * SilcBuffer silc_buffer_srealloc(SilcStack stack,
+ * SilcBuffer sb, SilcUInt32 newsize);
+ *
+ * DESCRIPTION
+ *
+ * Reallocates buffer. Old data is saved into the new buffer. The buffer
+ * is exact clone of the old one except that there is now more/less space
+ * at the end of buffer. Returns NULL if system is out of memory. This
+ * always returns `sb' unless `sb' was NULL.
+ *
+ * If the `newsize' is shorter than the current buffer size, the data
+ * and tail area of the buffer must be set to correct position before
+ * calling this function so that buffer overflow would not occur when
+ * the buffer size is reduced.
+ *
+ * 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_srealloc(SilcStack stack,
+ SilcBuffer sb, SilcUInt32 newsize)
+{
+ SilcUInt32 hlen, dlen;
+ unsigned char *h;
+
+ if (!stack)
+ return silc_buffer_realloc(sb, newsize);
+
+ if (!sb)
+ return silc_buffer_salloc(stack, newsize);
+
+ if (newsize == silc_buffer_truelen(sb))
+ return sb;
+
+ hlen = silc_buffer_headlen(sb);
+ dlen = silc_buffer_len(sb);
+ h = (unsigned char *)silc_srealloc(stack, silc_buffer_truelen(sb),
+ sb->head, newsize);