aboutsummaryrefslogtreecommitdiffstats
path: root/include/string.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/string.h141
1 files changed, 40 insertions, 101 deletions
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