From 3f867b936ec97b3d0c907fe6c68e2304c1f01216 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 12 Nov 2022 13:20:28 +0100 Subject: [PATCH] libc: Implement stpcpy This function is unsafe so it is marked as deprecated, but if programs need it they can use it. --- libs/libc/include/string.h | 5 +++++ libs/libc/src/string.cpp | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/libs/libc/include/string.h b/libs/libc/include/string.h index 7ce34c14..cdfb4dee 100644 --- a/libs/libc/include/string.h +++ b/libs/libc/include/string.h @@ -91,6 +91,11 @@ extern "C" __lc_deprecated("strcat is unsafe and should not be used; use strncat instead") char* strcat(char* dest, const char* src); +#ifdef _GNU_SOURCE + /* Copies the string src into dest, returning a pointer to the end of dest. */ + __lc_is_deprecated char* stpcpy(char* dest, const char* src); +#endif + char* strtok(char* str, const char* delim); // Not implemented. #ifdef __cplusplus diff --git a/libs/libc/src/string.cpp b/libs/libc/src/string.cpp index 974bc5cd..39f1d352 100644 --- a/libs/libc/src/string.cpp +++ b/libs/libc/src/string.cpp @@ -111,6 +111,13 @@ extern "C" return len; } + char* stpcpy(char* dest, const char* src) + { + size_t len = strlen(src); + size_t rc = strlcpy(dest, src, len + 1); + return dest + rc; + } + int strcmp(const char* a, const char* b) { while (*a && (*a == *b))