feat(string): complete string.h + strdup/memccpy

This commit is contained in:
2026-09-03 20:05:49 -04:00
parent 20f514d91c
commit 06d2ec7c34
19 changed files with 1860 additions and 2 deletions
+31
View File
@@ -0,0 +1,31 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
/*
* Copy src to dst including the terminating NUL; return dst. The strings
* must not overlap (restrict).
*
* The copy loop below is the canonical strcpy idiom; GCC's
* -ftree-loop-distribute-patterns (on by default at -O2 and -O3) can rewrite
* such loops into calls to the recognized string builtins — potentially this
* very function — causing infinite self-recursion. Disable that one
* transformation for this function only.
*/
__attribute__((optimize("no-tree-loop-distribute-patterns"))) char *
strcpy(char *restrict dst, const char *restrict src) // NOLINT(bugprone-*)
{
char *d = dst;
for (;;)
{
*d++ = *src;
if (*src == '\0')
{
return dst;
}
src++;
}
}