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