+2026-02-21 Bruno Haible <bruno@clisp.org>
+
+ strnul: New module.
+ Suggested by Alejandro Colomar <alx@kernel.org> in
+ <https://lists.gnu.org/archive/html/bug-gnulib/2026-02/msg00121.html>.
+ * lib/string.in.h (gl_strnul): New function.
+ (strnul): New macro or template.
+ * lib/string.c: Update comment.
+ * m4/string_h.m4 (gl_STRING_H_REQUIRE_DEFAULTS): Initialize
+ GNULIB_STRNUL.
+ * modules/string-h (Makefile.am): Substitute GNULIB_STRNUL.
+ * modules/strnul: New file.
+
2026-02-21 Bruno Haible <bruno@clisp.org>
streq: Rename to streq-opt.
-/* streq and memeq functions.
+/* streq, memeq, gl_strnul functions.
Copyright (C) 2025-2026 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
/* The following functions are not specified by POSIX. They are gnulib
extensions. */
+#if @GNULIB_STRNUL@
+/* Returns a pointer to the terminating NUL byte of STRING.
+ strnul (string)
+ This is a type-generic macro:
+ If STRING is a 'const char *', the result is 'const char *'.
+ If STRING is a 'char *', the result is 'char *'.
+ It is equivalent to
+ string + strlen (string)
+ or to
+ strchr (string, '\0'). */
+# ifdef __cplusplus
+extern "C" {
+# endif
+_GL_STRING_INLINE const char *gl_strnul (const char *string)
+ _GL_ATTRIBUTE_PURE
+ _GL_ARG_NONNULL ((1));
+_GL_STRING_INLINE const char *gl_strnul (const char *string)
+{
+ /* In gcc >= 7 or clang >= 4, we could use the expression
+ strchr (string, '\0')
+ because these compiler versions produce identical code for both
+ expressions. But this optimization in not available in older
+ compiler versions, and is also not available when the compiler
+ option '-fno-builtin' is in use. */
+ return string + strlen (string);
+}
+# ifdef __cplusplus
+}
+# endif
+# ifdef __cplusplus
+template <typename T> T strnul (T);
+template <> inline const char *strnul<const char *> (const char *s)
+{ return gl_strnul (s); }
+template <> inline char *strnul< char *> ( char *s)
+{ return const_cast<char *>(gl_strnul (s)); }
+# else
+# if (defined __GNUC__ && __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 && !defined __cplusplus) \
+ || (defined __clang__ && __clang_major__ >= 3) \
+ || (defined __SUNPRO_C && __SUNPRO_C >= 0x5150) \
+ || (__STDC_VERSION__ >= 201112L && !defined __GNUC__)
+/* The compiler supports _Generic from ISO C11. */
+# define strnul(s) \
+ _Generic (s, \
+ char * : (char *) gl_strnul (s), \
+ const char * : gl_strnul (s))
+# else
+# define strnul(s) \
+ ((char *) gl_strnul (s))
+# endif
+# endif
+#endif
+
#if @GNULIB_STR_STARTSWITH@
/* Returns true if STRING starts with PREFIX.
Returns false otherwise. */
# string_h.m4
-# serial 46
+# serial 47
dnl Copyright (C) 2007-2026 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRSTR])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRCASESTR])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOK_R])
+ gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRNUL])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STR_STARTSWITH])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STR_ENDSWITH])
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_MBSLEN])
-e 's/@''GNULIB_STRNCPY''@/$(GNULIB_STRNCPY)/g' \
-e 's/@''GNULIB_STRNDUP''@/$(GNULIB_STRNDUP)/g' \
-e 's/@''GNULIB_STRNLEN''@/$(GNULIB_STRNLEN)/g' \
+ -e 's/@''GNULIB_STRNUL''@/$(GNULIB_STRNUL)/g' \
-e 's/@''GNULIB_STRPBRK''@/$(GNULIB_STRPBRK)/g' \
-e 's/@''GNULIB_STRSEP''@/$(GNULIB_STRSEP)/g' \
-e 's/@''GNULIB_STRSTR''@/$(GNULIB_STRSTR)/g' \
--- /dev/null
+Description:
+strnul() function: return pointer to terminating NUL byte.
+
+Files:
+lib/string.c
+
+Depends-on:
+string-h
+
+configure.ac:
+gl_STRING_MODULE_INDICATOR([strnul])
+
+Makefile.am:
+lib_SOURCES += string.c
+
+Include:
+<string.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+all