summaryrefslogtreecommitdiff
path: root/src/common/mempattern.h
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-06-28 12:59:40 +0200
committerOndřej Surý <ondrej@sury.org>2013-06-28 12:59:40 +0200
commit124965832295a277b9ca6ae9fac4f45a74a36b2a (patch)
treef299e2335863f74e0be0707f84b85211baaf2d03 /src/common/mempattern.h
parent3d2d198c71a6b844b60fa9ef68801b66bba93361 (diff)
downloadknot-upstream/1.3.0_rc3.tar.gz
New upstream version 1.3.0~rc3upstream/1.3.0_rc3
Diffstat (limited to 'src/common/mempattern.h')
-rw-r--r--src/common/mempattern.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common/mempattern.h b/src/common/mempattern.h
index ebfe4ae..7bef851 100644
--- a/src/common/mempattern.h
+++ b/src/common/mempattern.h
@@ -27,6 +27,29 @@
#ifndef _KNOTD_COMMON_MALLOC_H_
#define _KNOTD_COMMON_MALLOC_H_
+#include <stddef.h>
+
+/* Memory allocation function prototypes. */
+typedef void* (*mm_alloc_t)(void* ctx, size_t len);
+typedef void (*mm_free_t)(void *p);
+typedef void (*mm_flush_t)(void *p);
+
+/* Memory allocation context. */
+typedef struct mm_ctx {
+ void *ctx; /* \note Must be first */
+ mm_alloc_t alloc;
+ mm_free_t free;
+} mm_ctx_t;
+
+/*! \brief Initialize default memory allocation context. */
+void mm_ctx_init(mm_ctx_t *mm);
+
+/*! \brief Allocate memory or die. */
+void* xmalloc(size_t l);
+
+/*! \brief Reallocate memory or die. */
+void *xrealloc(void *p, size_t l);
+
/*!
* \brief Reserve new or trim excessive memory.
*
@@ -64,6 +87,17 @@ int mreserve(char **p, size_t tlen, size_t min, size_t allow, size_t *reserved);
*/
char* sprintf_alloc(const char *fmt, ...);
+/*!
+ * \brief Create new string from a concatenation of s1 and s2.
+ *
+ * \param s1 First string.
+ * \param s2 Second string.
+ *
+ * \retval Newly allocated string on success.
+ * \retval NULL on error.
+ */
+char* strcdup(const char *s1, const char *s2);
+
/*! \brief Print usage statistics.
*
* \note This function has destructor attribute set if MEM_DEBUG is enabled.