aboutsummaryrefslogtreecommitdiff
path: root/src/xalloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xalloc.c')
-rw-r--r--src/xalloc.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/xalloc.c b/src/xalloc.c
new file mode 100644
index 0000000..d12a04c
--- /dev/null
+++ b/src/xalloc.c
@@ -0,0 +1,53 @@
+/* This file is part of vmod-binlog
+ Copyright (C) 2013 Sergey Poznyakoff
+
+ Vmod-binlog is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Vmod-binlog is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <config.h>
+#include <stdlib.h>
+#include <string.h>
+#include "xalloc.h"
+#include "err.h"
+
+void *
+xmalloc(size_t s)
+{
+ void *p = malloc(s);
+ if (!p) {
+ error("out of memory");
+ exit(1);
+ }
+ return p;
+}
+
+void *
+xcalloc(size_t count, size_t size)
+{
+ void *p;
+
+ size *= count;
+ p = xmalloc(count * size);
+ memset(p, 0, size);
+ return p;
+}
+
+void *
+xmemdup(void const *p, size_t s)
+{
+ return memcpy(xmalloc(s), p, s);
+}
+
+
+

Return to:

Send suggestions and report system problems to the System administrator.