summaryrefslogtreecommitdiffstats
path: root/macro.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-04-11 15:36:25 +0000
committerLennart Poettering <lennart@poettering.net>2008-04-11 15:36:25 +0000
commit1559476e75534b4b4896a9fdb08f78af0ad7882e (patch)
treecb36479c0aa64d63188f3965e7458d440abdc833 /macro.h
parentfa49d80fd0bd59b54dd97351057f2b9bb9db60cc (diff)
commit what i prepared a while back
git-svn-id: file:///home/lennart/svn/public/libcanberra/trunk@5 01b60673-d06a-42c0-afdd-89cb8e0f78ac
Diffstat (limited to 'macro.h')
-rw-r--r--macro.h89
1 files changed, 89 insertions, 0 deletions
diff --git a/macro.h b/macro.h
new file mode 100644
index 0000000..26dca20
--- /dev/null
+++ b/macro.h
@@ -0,0 +1,89 @@
+#ifndef foocanberramacrohfoo
+#define foocanberramacrohfoo
+
+#include <stdio.h>
+#include <assert.h>
+
+#ifdef __GNUC__
+#define CA_PRETTY_FUNCTION __PRETTY_FUNCTION__
+#else
+#define CA_PRETTY_FUNCTION ""
+#endif
+
+#define ca_return_if_fail(expr) \
+ do { \
+ if (!(expr)) { \
+ fprintf(stderr, "%s: Assertion <%s> failed.\n", CA_PRETTY_FUNCTION, #expr ); \
+ return; \
+ } \
+ } while(0)
+
+#define ca_return_val_if_fail(expr, val) \
+ do { \
+ if (!(expr)) { \
+ fprintf(stderr, "%s: Assertion <%s> failed.\n", CA_PRETTY_FUNCTION, #expr ); \
+ return (val); \
+ } \
+ } while(0)
+
+#define ca_assert assert
+
+/* An assert which guarantees side effects of x */
+#ifdef NDEBUG
+#define ca_assert_se(x) x
+#else
+#define ca_assert_se(x) ca_assert(x)
+#endif
+
+#define ca_assert_not_reached() ca_assert(!"Should not be reached.")
+
+#define ca_assert_success(x) do { \
+ int _r = (x); \
+ ca_assert(_r == 0); \
+ } while(0)
+
+#define CA_ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
+
+#ifndef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+#endif
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+#ifndef CLAMP
+#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
+#endif
+
+#ifndef FALSE
+#define FALSE (0)
+#endif
+
+#ifndef TRUE
+#define TRUE (!FALSE)
+#endif
+
+#define CA_PTR_TO_UINT(p) ((unsigned int) (unsigned long) (p))
+#define CA_UINT_TO_PTR(u) ((void*) (unsigned long) (u))
+
+#define CA_PTR_TO_UINT32(p) ((uint32_t) CA_PTR_TO_UINT(p))
+#define CA_UINT32_TO_PTR(u) CA_UINT_TO_PTR((uint32_t) u)
+
+#define CA_PTR_TO_INT(p) ((int) CA_PTR_TO_UINT(p))
+#define CA_INT_TO_PTR(u) CA_UINT_TO_PTR((int) u)
+
+#define CA_PTR_TO_INT32(p) ((int32_t) CA_PTR_TO_UINT(p))
+#define CA_INT32_TO_PTR(u) CA_UINT_TO_PTR((int32_t) u)
+
+static inline size_t ca_align(size_t l) {
+ return (((l + sizeof(void*) - 1) / sizeof(void*)) * sizeof(void*));
+}
+
+#define CA_ALIGN(x) (ca_align(x))
+
+typedef void (*ca_free_cb_t)(void *);
+
+typedef int ca_bool_t;
+
+#endif