Files
vlibc/src/string/strcpy.c
T

32 lines
816 B
C

#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++;
}
}