aboutsummaryrefslogtreecommitdiffstats
path: root/include/slibc/features.h
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-11-14 02:51:33 +0100
committerMattias Andrée <maandree@operamail.com>2015-11-14 02:51:33 +0100
commit2b764051e4f75ac8868ba4371c53c3aecc8e72c8 (patch)
tree69af44be9fc6adf8d5fa67261556712b1203fd3a /include/slibc/features.h
parentm (diff)
downloadslibc-2b764051e4f75ac8868ba4371c53c3aecc8e72c8.tar.gz
slibc-2b764051e4f75ac8868ba4371c53c3aecc8e72c8.tar.bz2
slibc-2b764051e4f75ac8868ba4371c53c3aecc8e72c8.tar.xz
m slibc-human.h
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r--include/slibc/features.h92
1 files changed, 88 insertions, 4 deletions
diff --git a/include/slibc/features.h b/include/slibc/features.h
index 6951ea4..bb28189 100644
--- a/include/slibc/features.h
+++ b/include/slibc/features.h
@@ -29,6 +29,17 @@
/**
+ * Update existance of `__const_correct*` macros
+ */
+#ifdef __CONST_CORRECT
+# undef __CONST_CORRECT
+# undef __const_correct
+# undef __const_correct2
+# undef __const_correct2p
+#endif
+
+
+/**
* Macro for any function with at least 2 arguments,
* that shall return with `const` qualifier if and only
* if the first argument is `const`-qualifier.
@@ -48,10 +59,6 @@
* @param ... The rest of the arguments.
* @return The result casted to the same type as `first`.
*/
-#ifdef __CONST_CORRECT
-# undef __CONST_CORRECT
-# undef __const_correct
-#endif
#if defined(__GNUC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define __CONST_CORRECT
# define __const_correct(function, first, ...) \
@@ -81,6 +88,83 @@
* than using a fall back. */
+/**
+ * Macro for any function with at least 3 arguments,
+ * that shall return with `const` qualifier if and only
+ * if the second argument is `const`-qualifier.
+ *
+ * Other qualifiers could be dropped.
+ *
+ * @param function The name of the function.
+ * @param first The first argument.
+ * @param second The second argument.
+ * @param ... The rest of the arguments.
+ * @return The result casted to the same type as `second`.
+ */
+#if defined(__GNUC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+# define __CONST_CORRECT
+# define __const_correct2(function, first, second, ...) \
+ (_Generic(&(second), \
+ const wchar_t(*)[]: (const wchar_t*)function(first, second, __VA_ARGS__), \
+ const char(*)[]: (const char*) function(first, second, __VA_ARGS__), \
+ const void**: (const void*) function(first, second, __VA_ARGS__), \
+ void**: function(first, second, __VA_ARGS__), \
+ default: (__typeof__(&*first))function(first, second, __VA_ARGS__)))
+#elif defined(__GNUC__)
+# define __CONST_CORRECT
+# define __const_correct2(function, first, second, ...) \
+ ((__typeof__(&*second))function(first, second, __VA_ARGS__))
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+# define __CONST_CORRECT
+# define __const_correct2(function, first, second, ...) \
+ (_Generic(&(second), \
+ const wchar_t(*)[]: (const wchar_t*)function(first, second, __VA_ARGS__), \
+ const char(*)[]: (const char*) function(first, second, __VA_ARGS__), \
+ const wchar_t**: (const wchar_t*)function(first, second, __VA_ARGS__), \
+ const char**: (const char*) function(first, second, __VA_ARGS__), \
+ const void**: (const void*) function(first, second, __VA_ARGS__), \
+ default: function(first, second, __VA_ARGS__)))
+#endif
+
+
+/**
+ * Macro for any function with precisely 2 arguments,
+ * that shall return with `const` qualifier if and only
+ * if the second argument is `const`-qualifier.
+ *
+ * Other qualifiers could be dropped.
+ *
+ * @param function The name of the function.
+ * @param first The first argument.
+ * @param second The second argument.
+ * @return The result casted to the same type as `second`.
+ */
+#if defined(__GNUC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+# define __CONST_CORRECT
+# define __const_correct2p(function, first, second) \
+ (_Generic(&(second), \
+ const wchar_t(*)[]: (const wchar_t*)function(first, second), \
+ const char(*)[]: (const char*) function(first, second), \
+ const void**: (const void*) function(first, second), \
+ void**: function(first, second), \
+ default: (__typeof__(&*first))function(first, second)))
+#elif defined(__GNUC__)
+# define __CONST_CORRECT
+# define __const_correct2p(function, first, second) \
+ ((__typeof__(&*second))function(first, second))
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+# define __CONST_CORRECT
+# define __const_correct2p(function, first, second) \
+ (_Generic(&(second), \
+ const wchar_t(*)[]: (const wchar_t*)function(first, second), \
+ const char(*)[]: (const char*) function(first, second), \
+ const wchar_t**: (const wchar_t*)function(first, second), \
+ const char**: (const char*) function(first, second), \
+ const void**: (const void*) function(first, second), \
+ default: function(first, second)))
+#endif
+
+
/**
* _BSD_SOURCE || _SVID_SOURCE || _GNU_SOURCE implies _POSIX_C_SOURCE = 2.