Add common macros which can be useful in faultd
authorKrzysztof Opasiak <k.opasiak@samsung.com>
Mon, 8 May 2017 20:46:32 +0000 (22:46 +0200)
committerKrzysztof Opasiak <k.opasiak@samsung.com>
Tue, 9 May 2017 11:40:23 +0000 (13:40 +0200)
Signed-off-by: Krzysztof Opasiak <k.opasiak@samsung.com>
src/util/common.h [new file with mode: 0644]

diff --git a/src/util/common.h b/src/util/common.h
new file mode 100644 (file)
index 0000000..5cb1316
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * faultd
+ *
+ * Copyright © 2017 Samsung Electronics
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef FAULTD_COMMON_H
+#define FAULTD_COMMON_H
+
+#include <stdlib.h>
+
+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*a))
+
+#ifndef offsetof
+#define offsetof(type, member)  __builtin_offsetof (type, member)
+#endif /* offsetof */
+
+#ifndef container_of
+#define container_of(ptr, type, field) ({                               \
+        const typeof(((type *)0)->field) *member = (ptr);               \
+        (type *)( (char *)member - offsetof(type, field) );             \
+})
+#endif /* container_of */
+
+#define _cleanup_(x) __attribute__((cleanup(x)))
+
+static inline void freep(void *p)
+{
+  free(*(void**)p);
+}
+#define _cleanup_free_ _cleanup_(freep)
+
+#endif /* FAULTD_COMMON_H */