On 2026-02-20 17:17, Bruno Haible wrote:
But if you define
#define strnul(s) strchr(s, '\0')
it will be const-generic as soon as strchr(3) becomes const-generic in
libc. Wouldn't that be enough?
For a macro, this would be enough. But as Paul said, we also need it
as a function.
Come to think of it, perhaps that's good enough for a first
implementation. Although the function should be there, it cannot be
const-generic in C. So we could do something similar to what Alejandro
proposed earlier, except simpler. E.g.:
#if @GNULIB_STRNUL@
/* Return the address of the null byte at the end of STR. */
_GL_EXTERN_C char *strnul (char const *str)
_GL_ATTRIBUTE_PURE _GL_ARG_NONNULL ((1));
# define strnul(str) strchr (str, '\0')
#endif
with all the usual machinery, such as a lib/strnul.c to define the
function by using the macro. This should suffice for C; I don't know
about C++.
Although in some cases this wouldn't be quite as efficient as what I
suggested earlier, it would be qualifier-generic if strchr is, and it
would be simpler to implement. We could worry about tuning it later if
we have the time.