summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2015-02-06 17:26:41 +0100
committerTobias Klauser <tklauser@distanz.ch>2015-02-06 17:26:41 +0100
commit70d3f132f12423a43ee5454f747f58fdde4dfb8e (patch)
treef8be3d0ccaeea6728abe62ec8e41544c3c74a44b /util.h
Initial import, still work in progress
Diffstat (limited to 'util.h')
-rw-r--r--util.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..8a21467
--- /dev/null
+++ b/util.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2014-2015 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2009-2012 Daniel Borkmann
+ *
+ * This file is part of llmnrd.
+ *
+ * llmnrd 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, version 2 of the License.
+ *
+ * llmnrd 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 llmnrd. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTIL_H
+#define UTIL_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "compiler.h"
+
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+
+/*
+ * min() macro with strict type-checking.
+ * Taken from linux/kernel.h
+ */
+#undef min
+#define min(x, y) ({ \
+ typeof(x) _min1 = (x); \
+ typeof(y) _min2 = (y); \
+ (void) (&_min1 == &_min2); \
+ _min1 < _min2 ? _min1 : _min2; })
+
+static inline void __noreturn panic(const char *fmt, ...)
+{
+ va_list vl;
+
+ va_start(vl, fmt);
+ vfprintf(stderr, fmt, vl);
+ va_end(vl);
+
+ exit(EXIT_FAILURE);
+}
+
+void *xmalloc(size_t size);
+void *xzalloc(size_t size);
+void *xrealloc(void *ptr, size_t size);
+char *xstrdup(const char *s);
+
+#endif /* UTIL_H */