diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-03 13:53:47 +0100 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-17 16:42:38 +0100 |
| commit | f25b3c3cb5fd1e00521b91d575da0177dbb44ddc (patch) | |
| tree | bbb8240618d623d397ebfcb1ac59fda874934bc2 /libs | |
| parent | 880cd2194507c95449949f799d48a4b8ff3e0cd5 (diff) | |
| download | teachos-f25b3c3cb5fd1e00521b91d575da0177dbb44ddc.tar.xz teachos-f25b3c3cb5fd1e00521b91d575da0177dbb44ddc.zip | |
implement memset
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/include/kstd/cstring | 2 | ||||
| -rw-r--r-- | libs/kstd/src/libc/string.cpp | 16 |
2 files changed, 16 insertions, 2 deletions
diff --git a/libs/kstd/include/kstd/cstring b/libs/kstd/include/kstd/cstring index e97ecac..06932a4 100644 --- a/libs/kstd/include/kstd/cstring +++ b/libs/kstd/include/kstd/cstring @@ -9,8 +9,10 @@ namespace kstd::libc extern "C" { auto memcpy(void * dest, void const * src, std::size_t size) -> void *; + auto memset(void * dest, std::byte value, std::size_t size) -> void *; auto memmove(void * dest, void const * src, std::size_t size) -> void *; auto memcmp(void const * lhs, void const * rhs, std::size_t size) -> std::size_t; + auto strlen(char const * string) -> std::size_t; } diff --git a/libs/kstd/src/libc/string.cpp b/libs/kstd/src/libc/string.cpp index 4e264f9..302046d 100644 --- a/libs/kstd/src/libc/string.cpp +++ b/libs/kstd/src/libc/string.cpp @@ -22,9 +22,16 @@ namespace kstd::libc return dest;
}
- auto strlen(char const * string) -> std::size_t
+ auto memset(void * dest, std::byte value, std::size_t size) -> void *
{
- return std::distance(string, std::ranges::find(string, nullptr, '\0'));
+ auto dest_span = std::span{static_cast<std::byte *>(dest), size};
+
+ for (std::size_t i = 0; i < size; ++i)
+ {
+ dest_span[i] = value;
+ }
+
+ return dest;
}
auto memcmp(void const * lhs, void const * rhs, std::size_t size) -> std::size_t
@@ -62,4 +69,9 @@ namespace kstd::libc return dest;
}
+ auto strlen(char const * string) -> std::size_t
+ {
+ return std::distance(string, std::ranges::find(string, nullptr, '\0'));
+ }
+
} // namespace kstd::libc
\ No newline at end of file |
