From 38320018dcee8e333291ee23babb2573d3536eaf Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 30 Sep 2023 20:58:19 +0300 Subject: [PATCH] LibC: Implement stpcpy since gcc seems to need it gcc seems to optimize some calls to strcpy to stpcpy --- libc/string.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libc/string.cpp b/libc/string.cpp index 3f4ba105..5991bd5d 100644 --- a/libc/string.cpp +++ b/libc/string.cpp @@ -62,12 +62,18 @@ int strcmp(const char* s1, const char* s2) return *u1 - *u2; } -char* strcpy(char* __restrict__ dest, const char* __restrict__ src) +char* stpcpy(char* __restrict__ dest, const char* __restrict__ src) { - size_t i; - for (i = 0; src[i]; i++) + size_t i = 0; + for (; src[i]; i++) dest[i] = src[i]; dest[i] = '\0'; + return &dest[i]; +} + +char* strcpy(char* __restrict__ dest, const char* __restrict__ src) +{ + stpcpy(dest, src); return dest; }