|
|
Message-ID: <a32505bd85954033f4626f3ee381f64072662383.1771849171.git.alx@kernel.org>
Date: Mon, 23 Feb 2026 13:22:21 +0100
From: Alejandro Colomar <alx@...nel.org>
To: musl@...ts.openwall.com
Cc: Paul Eggert <eggert@...ucla.edu>, Bruno Haible <bruno@...sp.org>,
Joseph Myers <josmyers@...hat.com>, Alejandro Colomar <alx@...nel.org>,
Markus Wichmann <nullplan@....net>, Rich Felker <dalias@...c.org>,
Luca Kellermann <mailto.luca.kellermann@...il.com>
Subject: [PATCH v7 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 83e2b946486f..375fb5261cbd 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*){0})
+#define __QCharptrof(s) typeof \
+( \
+ _Generic((__QVoidptrof(s)){0}, \
+ 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, ...) ((__QVoidptrof(p)) memchr(p, __VA_ARGS__))
+# define strchr(s, ...) ((__QCharptrof(s)) strchr(s, __VA_ARGS__))
+# define strrchr(s, ...) ((__QCharptrof(s)) strrchr(s, __VA_ARGS__))
+# define strpbrk(s, ...) ((__QCharptrof(s)) strpbrk(s, __VA_ARGS__))
+# define strstr(s, ...) ((__QCharptrof(s)) strstr(s, __VA_ARGS__))
+#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, ...) ((__QVoidptrof(p)) memmem(p, __VA_ARGS__))
+# 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, ...) ((__QCharptrof(s)) strchrnul(s, __VA_ARGS__))
+# define strcasestr(s, ...) ((__QCharptrof(s)) strcasestr(s, __VA_ARGS__))
+# define memrchr(p, ...) ((__QVoidptrof(p)) memrchr(p, __VA_ARGS__))
+# 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.