diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-10-15 04:33:05 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-10-15 04:33:05 +0200 |
commit | 60641f7913d527ee7ae0515640b934ec7b777bc2 (patch) | |
tree | 7edf8ca676d97a70c53aaf9fa1f77bd7b5560da9 /include | |
parent | solve the const-correct problem for functions, in wchar.h, such as wcschr (requires C11 and this thus only applied if compiling with C11) (diff) | |
download | slibc-60641f7913d527ee7ae0515640b934ec7b777bc2.tar.gz slibc-60641f7913d527ee7ae0515640b934ec7b777bc2.tar.bz2 slibc-60641f7913d527ee7ae0515640b934ec7b777bc2.tar.xz |
better solution to returning const if input is const, only requires C99 (actually: C99-capable version of GCC) and GCC, or C11
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/slibc/features.h | 54 | ||||
-rw-r--r-- | include/string.h | 141 | ||||
-rw-r--r-- | include/wchar.h | 142 |
3 files changed, 135 insertions, 202 deletions
diff --git a/include/slibc/features.h b/include/slibc/features.h index 499e4f6..b5b28eb 100644 --- a/include/slibc/features.h +++ b/include/slibc/features.h @@ -29,6 +29,60 @@ /** + * 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. + * + * Other qualifiers could be dropped. + * + * Usage example: + * ``` + * char* strchr(const char*, int) + * #ifdef __CONST_CORRECT + * # define strchr(...) __const_correct(strchr, __VA_ARGS__) + * #endif + * ``` + * + * @param function The name of the function. + * @param first The first argument. + * @param ... The rest of the arguments. + * @return The result casted to the same type as `first`. + */ +#if defined(__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, ...) \ + (_Generic(&(first), \ + const wchar_t(*)[]: (const wchar_t*)function(first, __VA_ARGS__), \ + const char(*)[]: (const char*) function(first, __VA_ARGS__), \ + const void**: (const void*) function(first, __VA_ARGS__), \ + void**: function(first, __VA_ARGS__), \ + default: (__typeof__(&*first))function(first, __VA_ARGS__))) +#elif defined(__GNUC__) +# define __CONST_CORRECT +# define __const_correct(function, first, ...) \ + ((__typeof__(&*first))function(first, __VA_ARGS__)) +#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) +# define __CONST_CORRECT +# define __const_correct(function, first, ...) \ + (_Generic(&(first), \ + const wchar_t(*)[]: (const wchar_t*)function(first, __VA_ARGS__), \ + const char(*)[]: (const char*) function(first, __VA_ARGS__), \ + const wchar_t**: (const wchar_t*)function(first, __VA_ARGS__), \ + const char**: (const char*) function(first, __VA_ARGS__), \ + const void**: (const void*) function(first, __VA_ARGS__), \ + default: function(first, __VA_ARGS__))) +#endif +/* Note, string literals are compiler-dependent. Does not work too well in GCC. */ +/* Note, __VA_ARGS__ requires, C99, therefore we need __CONST_CORRECT, rather + * than using a fall back. */ + + + +/** * _BSD_SOURCE || _SVID_SOURCE || _GNU_SOURCE implies _POSIX_C_SOURCE = 2. */ #if defined(__BSD_SOURCE) || defined(__SVID_SOURCE) || defined(__GNU_SOURCE) diff --git a/include/string.h b/include/string.h index 4fa91ca..9dae6af 100644 --- a/include/string.h +++ b/include/string.h @@ -791,11 +791,8 @@ int strverscmp(const char*, const char*) */ void* memchr(const void*, int, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define memchr(segment, c, size) \ - (_Generic((segment), \ - const void*: (const void*)memchr(segment, c, size), \ - void*: memchr(segment, c, size))) +#ifdef __CONST_CORRECT +# define memchr(...) (__const_correct(memchr, __VA_ARGS__)) #endif @@ -812,12 +809,8 @@ void* memchr(const void*, int, size_t) */ void* rawmemchr(const void*, int) __GCC_ONLY(__attribute__((warn_unused_result, returns_nonnull, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define rawmemchr(segment, c) \ - (_Generic((segment), \ - const void*: (const void*)rawmemchr(segment, c), \ - void*: rawmemchr(segment, c))) -# endif +#ifdef __CONST_CORRECT +# define rawmemchr(...) (__const_correct(rawmemchr, __VA_ARGS__)) #endif /** @@ -835,11 +828,8 @@ void* rawmemchr(const void*, int) */ void* memrchr(const void*, int, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define memrchr(segment, c, size) \ - (_Generic((segment), \ - const void*: (const void*)memrchr(segment, c, size), \ - void*: memrchr(segment, c, size))) +#ifdef __CONST_CORRECT +# define memrchr(...) (__const_correct(memrchr, __VA_ARGS__)) #endif /** @@ -857,11 +847,8 @@ void* memrchr(const void*, int, size_t) */ char* strchr(const char*, int) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strchr(string, c) \ - (_Generic((string), \ - const char*: (const char*)strchr(string, c), \ - char*: strchr(string, c))) +#ifdef __CONST_CORRECT +# define strchr(...) (__const_correct(strchr, __VA_ARGS__)) #endif #if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE) @@ -880,12 +867,9 @@ char* strchr(const char*, int) * if none were found. */ char* strchrnul(const char*, int) - __GCC_ONLY(__attribute__((warn_unused_result, returns_nonnull, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strchrnul(string, c) \ - (_Generic((string), \ - const char*: (const char*)strchrnul(string, c), \ - char*: strchrnul(string, c))) + __GCC_ONLY(__attribute__((warn_unused_result, returns_nonnull, nonnull, pure))); +# ifdef __CONST_CORRECT +# define strchrnul(...) (__const_correct(strchrnul, __VA_ARGS__)) # endif #endif @@ -905,11 +889,8 @@ char* strchrnul(const char*, int) */ char* strrchr(const char*, int) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strrchr(string, c) \ - (_Generic((string), \ - const char*: (const char*)strrchr(string, c), \ - char*: strrchr(string, c))) +#ifdef __CONST_CORRECT +# define strrchr(...) (__const_correct(strrchr, __VA_ARGS__)) #endif @@ -924,11 +905,8 @@ char* strrchr(const char*, int) */ char* strstr(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strstr(haystack, needle) \ - (_Generic((haystack), \ - const char*: (const char*)strstr(haystack, needle), \ - char*: strstr(haystack, needle))) +#ifdef __CONST_CORRECT +# define strstr(...) (__const_correct(strstr, __VA_ARGS__)) #endif /** @@ -942,11 +920,8 @@ char* strstr(const char*, const char*) */ char* strcasestr(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strcasestr(haystack, needle) \ - (_Generic((haystack), \ - const char*: (const char*)strcasestr(haystack, needle), \ - char*: strcasestr(haystack, needle))) +#ifdef __CONST_CORRECT +# define strcasestr(...) (__const_correct(strcasestr, __VA_ARGS__)) #endif #if defined(__SLIBC_SOURCE) @@ -965,11 +940,8 @@ char* strcasestr(const char*, const char*) */ char* strnstr(const char*, const char*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strnstr(haystack, needle, maxlen) \ - (_Generic((haystack), \ - const char*: (const char*)strnstr(haystack, needle, maxlen), \ - char*: strnstr(haystack, needle, maxlen))) +# ifdef __CONST_CORRECT +# define strnstr(...) (__const_correct(strnstr, __VA_ARGS__)) # endif /** @@ -986,11 +958,8 @@ char* strnstr(const char*, const char*, size_t) */ char* strncasestr(const char*, const char*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strncasestr(haystack, needle, maxlen) \ - (_Generic((haystack), \ - const char*: (const char*)strncasestr(haystack, needle, maxlen), \ - char*: strncasestr(haystack, needle, maxlen))) +# ifdef __CONST_CORRECT +# define strncasestr(...) (__const_correct(strncasestr, __VA_ARGS__)) # endif /** @@ -1006,11 +975,8 @@ char* strncasestr(const char*, const char*, size_t) */ char* rawstrstr(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define rawstrstr(haystack, needle) \ - (_Generic((haystack), \ - const char*: (const char*)rawstrstr(haystack, needle), \ - char*: rawstrstr(haystack, needle))) +# ifdef __CONST_CORRECT +# define rawstrstr(...) (__const_correct(rawstrstr, __VA_ARGS__)) # endif /** @@ -1026,11 +992,8 @@ char* rawstrstr(const char*, const char*) */ char* rawstrcasestr(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define rawstrcasestr(haystack, needle) \ - (_Generic((haystack), \ - const char*: (const char*)rawstrcasestr(haystack, needle), \ - char*: rawstrcasestr(haystack, needle))) +# ifdef __CONST_CORRECT +# define rawstrcasestr(...) (__const_correct(rawstrcasestr, __VA_ARGS__)) # endif /** @@ -1049,11 +1012,8 @@ char* rawstrcasestr(const char*, const char*) */ void* memcasemem(const void*, size_t, const void*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define memcasemem(haystack, haystack_length, needle, needle_length) \ - (_Generic((haystack), \ - const void*: (const void*)memcasemem(haystack, haystack_length, needle, needle_length), \ - void*: memcasemem(haystack, haystack_length, needle, needle_length))) +# ifdef __CONST_CORRECT +# define memcasemem(...) (__const_correct(memcasemem, __VA_ARGS__)) # endif /** @@ -1069,11 +1029,8 @@ void* memcasemem(const void*, size_t, const void*, size_t) */ char* strstarts(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strstarts(string, desired) \ - (_Generic((string), \ - const char*: (const char*)strstarts(string, desired), \ - char*: strstarts(string, desired))) +# ifdef __CONST_CORRECT +# define strstarts(...) (__const_correct(strstarts, __VA_ARGS__)) # endif /** @@ -1089,11 +1046,8 @@ char* strstarts(const char*, const char*) */ char* strends(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strends(string, desired) \ - (_Generic((string), \ - const char*: (const char*)strends(string, desired), \ - char*: strends(string, desired))) +# ifdef __CONST_CORRECT +# define strends(...) (__const_correct(strends, __VA_ARGS__)) # endif /** @@ -1109,11 +1063,8 @@ char* strends(const char*, const char*) */ char* strcasestarts(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strcasestarts(string, desired) \ - (_Generic((string), \ - const char*: (const char*)strcasestarts(string, desired), \ - char*: strcasestarts(string, desired))) +# ifdef __CONST_CORRECT +# define strcasestarts(...) (__const_correct(strcasestarts, __VA_ARGS__)) # endif /** @@ -1129,11 +1080,8 @@ char* strcasestarts(const char*, const char*) */ char* strcaseends(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strcaseends(string, desired) \ - (_Generic((string), \ - const char*: (const char*)strcaseends(string, desired), \ - char*: strcaseends(string, desired))) +# ifdef __CONST_CORRECT +# define strcaseends(...) (__const_correct(strcaseends, __VA_ARGS__)) # endif #endif @@ -1154,11 +1102,8 @@ char* strcaseends(const char*, const char*) */ void* memmem(const void*, size_t, const void*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define memmem(haystack, haystack_length, needle, needle_length) \ - (_Generic((haystack), \ - const void*: (const void*)memmem(haystack, haystack_length, needle, needle_length), \ - void*: memmem(haystack, haystack_length, needle, needle_length))) +# ifdef __CONST_CORRECT +# define memmem(...) (__const_correct(memmem, __VA_ARGS__)) # endif #endif @@ -1204,11 +1149,8 @@ size_t strcspn(const char*, const char*) */ char* strpbrk(const char*, const char*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define strpbrk(string, stopset) \ - (_Generic((string), \ - const void*: (const void*)strpbrk(string, stopset), \ - void*: strpbrk(string, stopset))) +#ifdef __CONST_CORRECT +# define strpbrk(...) (__const_correct(strpbrk, __VA_ARGS__)) #endif @@ -1287,10 +1229,7 @@ char* strsep(char** restrict, const char* restrict) char* __gnu_basename(const char*) __GCC_ONLY(__attribute__((warn_unused_result, pure))); # define basename __gnu_basename -/* It does not look like it is possible to solve the - * const-correctness problem here. We cannot use - * _Generic in the macro `basename` here. That would - * stop us from getting a pointer to the function. */ +/* It does not look like it is possible to solve the const-correctness problem here. */ #endif diff --git a/include/wchar.h b/include/wchar.h index 29237a6..aade683 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -744,11 +744,8 @@ int wcsncasecmp(const wchar_t*, const wchar_t*, size_t) */ wchar_t* wmemchr(const wchar_t*, wchar_t, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wmemchr(segment, c, size) \ - (_Generic((segment), \ - const wchar_t*: (const wchar_t*)wmemchr(segment, c, size), \ - wchar_t*: wmemchr(segment, c, size))) +#ifdef __CONST_CORRECT +# define wmemchr(...) (__const_correct(wmemchr, __VA_ARGS__)) #endif #if defined(__SLIBC_SOURCE) @@ -765,12 +762,9 @@ wchar_t* wmemchr(const wchar_t*, wchar_t, size_t) */ wchar_t* rawwmemchr(const wchar_t*, wchar_t) __GCC_ONLY(__attribute__((warn_unused_result, returns_nonnull, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define rawwmemchr(segment, c) \ - (_Generic((segment), \ - const wchar_t*: (const wchar_t*)rawwmemchr(segment, c), \ - wchar_t*: rawwmemchr(segment, c))) -# endif +#ifdef __CONST_CORRECT +# define rawwmemchr(...) (__const_correct(rawwmemchr, __VA_ARGS__)) +#endif /** * Find the last occurrence of a wide character in @@ -790,11 +784,8 @@ wchar_t* rawwmemchr(const wchar_t*, wchar_t) */ wchar_t* wmemrchr(const wchar_t*, wchar_t, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wmemrchr(segment, c, size) \ - (_Generic((segment), \ - const wchar_t*: (const wchar_t*)wmemrchr(segment, c, size), \ - wchar_t*: wmemrchr(segment, c, size))) +# ifdef __CONST_CORRECT +# define wmemrchr(...) (__const_correct(wmemrchr, __VA_ARGS__)) # endif #endif @@ -810,11 +801,8 @@ wchar_t* wmemrchr(const wchar_t*, wchar_t, size_t) */ wchar_t* wcschr(const wchar_t*, wchar_t) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcschr(string, c) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcschr(string, c), \ - wchar_t*: wcschr(string, c))) +#ifdef __CONST_CORRECT +# define wcschr(...) (__const_correct(wcschr, __VA_ARGS__)) #endif #if defined(__GNU_SOURCE) @@ -835,11 +823,8 @@ wchar_t* wcschr(const wchar_t*, wchar_t) */ wchar_t* wcschrnul(const wchar_t*, wchar_t) __GCC_ONLY(__attribute__((warn_unused_result, returns_nonnull, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcschrnul(string, c) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcschrnul(string, c), \ - wchar_t*: wcschrnul(string, c))) +# ifdef __CONST_CORRECT +# define wcschrnul(...) (__const_correct(wcschrnul, __VA_ARGS__)) # endif #endif @@ -859,11 +844,8 @@ wchar_t* wcschrnul(const wchar_t*, wchar_t) */ wchar_t* wcsrchr(const wchar_t*, wchar_t) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcsrchr(string, c) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcsrchr(string, c), \ - wchar_t*: wcsrchr(string, c))) +#ifdef __CONST_CORRECT +# define wcsrchr(...) (__const_correct(wcsrchr, __VA_ARGS__)) #endif @@ -873,11 +855,8 @@ wchar_t* wcsrchr(const wchar_t*, wchar_t) wchar_t* wcswcs(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))) __deprecated("Use 'wcsstr' instead."); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcswcs(haystack, needle) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)wcswcs(haystack, needle), \ - wchar_t*: wcswcs(haystack, needle))) +#ifdef __CONST_CORRECT +# define wcswcs(...) (__const_correct(wcswcs, __VA_ARGS__)) #endif /** @@ -891,11 +870,8 @@ wchar_t* wcswcs(const wchar_t*, const wchar_t*) */ wchar_t* wcsstr(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcsstr(haystack, needle) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)wcsstr(haystack, needle), \ - wchar_t*: wcsstr(haystack, needle))) +#ifdef __CONST_CORRECT +# define wcsstr(...) (__const_correct(wcsstr, __VA_ARGS__)) #endif #if defined(__SLIBC_SOURCE) @@ -912,11 +888,8 @@ wchar_t* wcsstr(const wchar_t*, const wchar_t*) */ wchar_t* wcscasestr(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcscasestr(haystack, needle) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)wcscasestr(haystack, needle), \ - wchar_t*: wcscasestr(haystack, needle))) +# ifdef __CONST_CORRECT +# define wcscasestr(...) (__const_correct(wcscasestr, __VA_ARGS__)) # endif /** @@ -934,11 +907,8 @@ wchar_t* wcscasestr(const wchar_t*, const wchar_t*) */ wchar_t* wcsnstr(const wchar_t*, const wchar_t*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcsnstr(haystack, needle, maxlen) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)wcsnstr(haystack, needle, maxlen), \ - wchar_t*: wcsnstr(haystack, needle, maxlen))) +# ifdef __CONST_CORRECT +# define wcsnstr(...) (__const_correct(wcsnstr, __VA_ARGS__)) # endif /** @@ -955,11 +925,8 @@ wchar_t* wcsnstr(const wchar_t*, const wchar_t*, size_t) */ wchar_t* wcsncasestr(const wchar_t*, const wchar_t*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcsncasestr(haystack, needle, maxlen) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)wcsncasestr(haystack, needle, maxlen), \ - wchar_t*: wcsncasestr(haystack, needle, maxlen))) +# ifdef __CONST_CORRECT +# define wcsncasestr(...) (__const_correct(wcsncasestr, __VA_ARGS__)) # endif /** @@ -975,11 +942,8 @@ wchar_t* wcsncasestr(const wchar_t*, const wchar_t*, size_t) */ wchar_t* rawwcsstr(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define rawwcsstr(haystack, needle) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)rawwcsstr(haystack, needle), \ - wchar_t*: rawwcsstr(haystack, needle))) +# ifdef __CONST_CORRECT +# define rawwcsstr(...) (__const_correct(rawwcsstr, __VA_ARGS__)) # endif /** @@ -995,11 +959,8 @@ wchar_t* rawwcsstr(const wchar_t*, const wchar_t*) */ wchar_t* rawwcscasestr(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, returns_nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define rawwcscasestr(haystack, needle) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)rawwcscasestr(haystack, needle), \ - wchar_t*: rawwcscasestr(haystack, needle))) +# ifdef __CONST_CORRECT +# define rawwcscasestr(...) (__const_correct(rawwcscasestr, __VA_ARGS__)) # endif /** @@ -1018,11 +979,8 @@ wchar_t* rawwcscasestr(const wchar_t*, const wchar_t*) */ wchar_t* wmemcasemem(const wchar_t*, size_t, const wchar_t*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wmemcasemem(haystack, haystack_length, needle, needle_length) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)wmemcasemem(haystack, haystack_length, needle, needle_length), \ - wchar_t*: wmemcasemem(haystack, haystack_length, needle, needle_length))) +# ifdef __CONST_CORRECT +# define wmemcasemem(...) (__const_correct(wmemcasemem, __VA_ARGS__)) # endif /** @@ -1038,11 +996,8 @@ wchar_t* wmemcasemem(const wchar_t*, size_t, const wchar_t*, size_t) */ wchar_t* wcsstarts(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcsstarts(string, desired) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcsstarts(string, desired), \ - wchar_t*: wcsstarts(string, desired))) +# ifdef __CONST_CORRECT +# define wcsstarts(...) (__const_correct(wcsstarts, __VA_ARGS__)) # endif /** @@ -1058,11 +1013,8 @@ wchar_t* wcsstarts(const wchar_t*, const wchar_t*) */ wchar_t* wcsends(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcsends(string, desired) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcsends(string, desired), \ - wchar_t*: wcsends(string, desired))) +# ifdef __CONST_CORRECT +# define wcsends(...) (__const_correct(wcsends, __VA_ARGS__)) # endif /** @@ -1078,11 +1030,8 @@ wchar_t* wcsends(const wchar_t*, const wchar_t*) */ wchar_t* wcscasestarts(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcscasestarts(string, desired) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcscasestarts(string, desired), \ - wchar_t*: wcscasestarts(string, desired))) +# ifdef __CONST_CORRECT +# define wcscasestarts(...) (__const_correct(wcscasestarts, __VA_ARGS__)) # endif /** @@ -1098,11 +1047,8 @@ wchar_t* wcscasestarts(const wchar_t*, const wchar_t*) */ wchar_t* wcscaseends(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcscaseends(string, desired) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcscaseends(string, desired), \ - wchar_t*: wcscaseends(string, desired))) +# ifdef __CONST_CORRECT +# define wcscaseends(...) (__const_correct(wcscaseends, __VA_ARGS__)) # endif #endif @@ -1124,11 +1070,8 @@ wchar_t* wcscaseends(const wchar_t*, const wchar_t*) */ wchar_t* wmemmem(const wchar_t*, size_t, const wchar_t*, size_t) __GCC_ONLY(__attribute__((warn_unused_result, pure))); -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wmemmem(haystack, haystack_length, needle, needle_length) \ - (_Generic((haystack), \ - const wchar_t*: (const wchar_t*)wmemmem(haystack, haystack_length, needle, needle_length), \ - wchar_t*: wmemmem(haystack, haystack_length, needle, needle_length))) +# ifdef __CONST_CORRECT +# define wmemmem(...) (__const_correct(wmemmem, __VA_ARGS__)) # endif #endif @@ -1174,11 +1117,8 @@ size_t wcscspn(const wchar_t*, const wchar_t*) */ wchar_t* wcspbrk(const wchar_t*, const wchar_t*) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) -# define wcspbrk(string, stopset) \ - (_Generic((string), \ - const wchar_t*: (const wchar_t*)wcspbrk(string, stopset), \ - wchar_t*: wcspbrk(string, stopset))) +#ifdef __CONST_CORRECT +# define wcspbrk(...) (__const_correct(wcspbrk, __VA_ARGS__)) #endif |