|
|
Message-ID: <b891d212fccb8681fa4d33c7e768579672fb69f4.1764260495.git.alx@kernel.org>
Date: Thu, 27 Nov 2025 17:27:27 +0100
From: Alejandro Colomar <alx@...nel.org>
To: musl@...ts.openwall.com
Cc: Alejandro Colomar <alx@...nel.org>, Markus Wichmann <nullplan@....net>
Subject: [PATCH v4 1/1] include/string.h: Implement QChar and QVoid wrappers
standardized in C23
Co-authored-by: Markus Wichmann <nullplan@....net>
Signed-off-by: Alejandro Colomar <alx@...nel.org>
---
include/string.h | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/include/string.h b/include/string.h
index 83e2b946..454d93a7 100644
--- a/include/string.h
+++ b/include/string.h
@@ -24,6 +24,15 @@ extern "C" {
#include <bits/alltypes.h>
+#define __QVoidptrof(p) typeof(1?(p):(void*)"")
+#define __QCharptrof(s) typeof \
+( \
+ _Generic(__QVoidptrof(s), \
+ const void *: (const char *) 0, \
+ void *: (char *) 0 \
+ ) \
+)
+
void *memcpy (void *__restrict, const void *__restrict, size_t);
void *memmove (void *, const void *, size_t);
void *memset (void *, int, size_t);
@@ -55,6 +64,14 @@ size_t strlen (const char *);
char *strerror (int);
+#if __STDC_VERSION__ >= 202311L
+# define memchr(p, chr) ((__QVoidptrof(p)) memchr(p, chr))
+# define strchr(s, chr) ((__QCharptrof(s)) strchr(s, chr))
+# define strrchr(s, chr) ((__QCharptrof(s)) strrchr(s, chr))
+# define strpbrk(s, chrs) ((__QCharptrof(s)) strpbrk(s, chrs))
+# define strstr(s, str) ((__QCharptrof(s)) strstr(s, str))
+#endif
+
#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#include <strings.h>
#endif
@@ -74,6 +91,9 @@ char *strerror_l (int, locale_t);
int strcoll_l (const char *, const char *, locale_t);
size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
void *memmem(const void *, size_t, const void *, size_t);
+# if __STDC_VERSION__ >= 202311L
+# define memmem(p, mem) ((__QVoidptrof(p)) memmem(p, mem))
+# endif
#endif
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
@@ -95,6 +115,11 @@ char *strchrnul(const char *, int);
char *strcasestr(const char *, const char *);
void *memrchr(const void *, int, size_t);
void *mempcpy(void *, const void *, size_t);
+# if __STDC_VERSION__ >= 202311L
+# define strchrnul(s, chr) ((__QCharptrof(s)) strchrnul(s, chr))
+# define strcasestr(s, str) ((__QCharptrof(s)) strcasestr(s, str))
+# define memrchr(p, chr) ((__QVoidptrof(p)) memrchr(p, chr))
+# endif
#endif
#ifdef __cplusplus
--
2.51.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.