+
+/* Following functions that use SilcStack as memory source. */
+
+/****f* silcutil/SilcMemoryAPI/silc_smalloc
+ *
+ * SYNOPSIS
+ *
+ * void *silc_smalloc(SilcStack stack, SilcUInt32 size);
+ *
+ * DESCRIPTION
+ *
+ * Allocate memory block of size of `size' from the stack indicated by
+ * `stack' and return pointer to it. Returns NULL on error. This
+ * function allocates aligned memory so it can be used to allocate
+ * memory for structures, for example.
+ *
+ * NOTES
+ *
+ * Be careful with this function: do not free the returned pointer
+ * explicitly and do not save the returned pointer to a permanent
+ * location.
+ *
+ * If `stack' is NULL this function calls silc_malloc.
+ *
+ ***/
+void *silc_smalloc(SilcStack stack, SilcUInt32 size);
+
+/****f* silcutil/SilcMemoryAPI/silc_scalloc
+ *
+ * SYNOPSIS
+ *
+ * void *silc_scalloc(SilcStack stack, SilcUInt32 items, SilcUInt32 size);
+ *
+ * DESCRIPTION
+ *
+ * Allocate memory block of size of `size' from the stack indicated by
+ * `stack', zero the memory area and return pointer to it. This
+ * function allocates aligned memory. Returns NULL on error.
+ *
+ * NOTES
+ *
+ * Be careful with this function: do not free the returned pointer
+ * explicitly and do not save the returned pointer to a permanent
+ * location.
+ *
+ * If `stack' is NULL this function calls silc_calloc.
+ *
+ ***/
+void *silc_scalloc(SilcStack stack, SilcUInt32 items, SilcUInt32 size);
+
+/****f* silcutil/SilcMemoryAPI/silc_srealloc
+ *
+ * SYNOPSIS
+ *
+ * void *silc_srealloc(SilcStack stack, SilcUInt32 old_size,
+ * void *ptr, SilcUInt32 size);
+ *
+ * DESCRIPTION
+ *
+ * Change the size of the memory block indicated by `ptr' to the new
+ * size of `size' bytes. The contents of `ptr' will not be changed.
+ * If `ptr' is NULL the call is equivalent to silc_smalloc. If `size'
+ * is zero (0) error will occur. Returns NULL on error and the old
+ * pointer remain intact. This may return different pointer from `ptr'
+ *
+ * NOTES
+ *
+ * If the reallocation from `stack' fails, this function will allocate
+ * new block of size of `size' bytes from `stack' and copy the data from
+ * `ptr' to the new memory block.
+ *
+ * If `stack' is NULL this function calls silc_realloc.
+ *
+ ***/
+void *silc_srealloc(SilcStack stack, SilcUInt32 old_size,
+ void *ptr, SilcUInt32 size);
+
+/****f* silcutil/SilcMemoryAPI/silc_smemdup
+ *
+ * SYNOPSIS
+ *
+ * void *silc_smemdup(SilcStack stack, const void *ptr, SilcUInt32 size);
+ *
+ * DESCRIPTION
+ *
+ * Duplicates the memory area indicated by `ptr' which is the size of
+ * `size' bytes. Returns pointer to the duplicated memory area. This
+ * NULL terminates the dupped memory area by allocating `size' + 1
+ * bytes, so this function can be used to duplicate strings that does not
+ * have NULL termination. This function allocates aligned memory so
+ * it can be used to duplicate also structures. Returns NULL on error.
+ *
+ * NOTES
+ *
+ * Be careful with this function: do not free the returned pointer
+ * explicitly and do not save the returned pointer to a permanent
+ * location.
+ *
+ * If `stack' is NULL this function calls silc_memdup.
+ *
+ ***/
+void *silc_smemdup(SilcStack stack, const void *ptr, SilcUInt32 size);
+
+/****f* silcutil/SilcMemoryAPI/silc_sfree
+ *
+ * SYNOPSIS
+ *
+ * void silc_scalloc(SilcStack stack, void *ptr);
+ *
+ * DESCRIPTION
+ *
+ * This function can be used to free the `ptr' if `stack' is NULL. This
+ * function does nothing if `stack' is non-NULL. When `stack' is NULL
+ * this function calls silc_free.
+ *
+ ***/
+void silc_sfree(SilcStack stack, void *ptr);
+
+/****f* silcutil/SilcMemoryAPI/silc_sstrdup
+ *
+ * SYNOPSIS
+ *
+ * char *silc_sstrdup(SilcStack stack, const char *str);
+ *
+ * DESCRIPTION
+ *
+ * Duplicates the string indicated by `str' and returns the duplicated
+ * string. Returns NULL on error.
+ *
+ * NOTES
+ *
+ * Be careful with this function: do not free the returned pointer
+ * explicitly and do not save the returned pointer to a permanent
+ * location.
+ *
+ * If `stack' is NULL this function calls silc_strdup.
+ *
+ ***/
+char *silc_sstrdup(SilcStack stack, const char *str);
+