summaryrefslogtreecommitdiffstats
path: root/include/c.h
diff options
context:
space:
mode:
authorKarel Zak2009-10-16 00:42:22 +0200
committerKarel Zak2009-10-16 00:57:50 +0200
commit4d0dbb8b634ab0ec833348502aff284598858696 (patch)
tree50365ccad451a1cf47131a464f1bfee5481837bc /include/c.h
parenttests: update fsck.ismounted test (diff)
downloadkernel-qcow2-util-linux-4d0dbb8b634ab0ec833348502aff284598858696.tar.gz
kernel-qcow2-util-linux-4d0dbb8b634ab0ec833348502aff284598858696.tar.xz
kernel-qcow2-util-linux-4d0dbb8b634ab0ec833348502aff284598858696.zip
include: add c.h with fundamental C definitions
Add: * ARRAY_SIZE with array type check * PATH_MAX, TRUE and FALSE macros * dummy __attribute__ for non-gcc compilers Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/c.h')
-rw-r--r--include/c.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/c.h b/include/c.h
new file mode 100644
index 000000000..413366b2e
--- /dev/null
+++ b/include/c.h
@@ -0,0 +1,49 @@
+/*
+ * Fundamental C definitions.
+ */
+
+#ifndef UTIL_LINUX_C_H
+#define UTIL_LINUX_C_H
+
+#include <limits.h>
+
+/*
+ * Compiler specific stuff
+ */
+#ifdef __GNUC__
+
+/* &a[0] degrades to a pointer: a different type from an array */
+# define __must_be_array(a) \
+ BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0])))
+
+#else /* !__GNUC__ */
+# define __must_be_array(a) 0
+# define __attribute__(_arg_)
+#endif /* !__GNUC__ */
+
+
+/* Force a compilation error if condition is true, but also produce a
+ * result (of value 0 and type size_t), so the expression can be used
+ * e.g. in a structure initializer (or where-ever else comma expressions
+ * aren't permitted).
+ */
+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
+
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
+#endif
+
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+
+#ifndef TRUE
+# define TRUE 1
+#endif
+
+#ifndef FALSE
+# define FALSE 0
+#endif
+
+#endif /* UTIL_LINUX_C_H */