From eadca3d25bb2763202a7a0ce6bc9706893e2eb96 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 18 Dec 2022 16:31:02 +0100 Subject: [PATCH] Add nullcpy() Invented function to memcpy() with a specific size, but add a null terminator. --- luna/include/luna/CString.h | 3 +++ luna/src/CString.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/luna/include/luna/CString.h b/luna/include/luna/CString.h index b1026be3..d677104a 100644 --- a/luna/include/luna/CString.h +++ b/luna/include/luna/CString.h @@ -12,4 +12,7 @@ extern "C" usize wcslen(const wchar_t* str); char* strdup(const char* str); + + // Copies len bytes from src into dest and adds a null terminator. + void nullcpy(char* dest, const char* src, usize len); } \ No newline at end of file diff --git a/luna/src/CString.cpp b/luna/src/CString.cpp index 79580e6f..7bb47ee7 100644 --- a/luna/src/CString.cpp +++ b/luna/src/CString.cpp @@ -65,4 +65,10 @@ extern "C" return dest; } + + void nullcpy(char* dest, const char* src, usize len) + { + memcpy(dest, src, len); + dest[len] = 0; + } } \ No newline at end of file