From a01b56ed39f6cd16064edbd4f521fb391ee42895 Mon Sep 17 00:00:00 2001 From: apio Date: Fri, 6 Jan 2023 16:20:35 +0100 Subject: [PATCH] CString: Support strcpy(), strcat() and strchr() --- luna/include/luna/CString.h | 5 +++++ luna/src/CString.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/luna/include/luna/CString.h b/luna/include/luna/CString.h index df46497c..b4ac3029 100644 --- a/luna/include/luna/CString.h +++ b/luna/include/luna/CString.h @@ -16,4 +16,9 @@ extern "C" // Copies len bytes from src into dest and adds a null terminator. void nullcpy(char* dest, const char* src, usize len); + + [[deprecated]] char* strcpy(char* dst, const char* src); + [[deprecated]] char* strcat(char* dst, const char* src); + + char* strchr(const char* str, int c); } diff --git a/luna/src/CString.cpp b/luna/src/CString.cpp index ac048c3c..06f129f6 100644 --- a/luna/src/CString.cpp +++ b/luna/src/CString.cpp @@ -81,4 +81,28 @@ extern "C" memcpy(dest, src, len); dest[len] = 0; } + + char* strcpy(char* dest, const char* src) + { + char* s = dest; + for (; *src; dest++, src++) *dest = *src; + *dest = 0; + return s; + } + + char* strcat(char* dest, const char* src) + { + char* s = dest; + while (*dest) dest++; + for (; *src; dest++, src++) *dest = *src; + *dest = 0; + return s; + } + + char* strchr(const char* str, int c) + { + while (*str && *str != c) str++; + if (*str) return const_cast(str); + return NULL; + } }