summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-10-16 10:31:04 +0200
committerLinus Groh <mail@linusgroh.de>2021-10-17 17:09:58 +0100
commit13e6d9d71a57d6127207af66b708f545719064da (patch)
treeb29822b2662554dae0772fe05a1dad1dcd37aa19 /Userland
parente6164d35fade3bd5e74ff2a06251e9e1eb1e3118 (diff)
downloadserenity-13e6d9d71a57d6127207af66b708f545719064da.zip
LibC: Implement wcslcpy
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibC/wchar.cpp12
-rw-r--r--Userland/Libraries/LibC/wchar.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/wchar.cpp b/Userland/Libraries/LibC/wchar.cpp
index 794fef19fe..9462f87c04 100644
--- a/Userland/Libraries/LibC/wchar.cpp
+++ b/Userland/Libraries/LibC/wchar.cpp
@@ -69,6 +69,18 @@ wchar_t* wcsncpy(wchar_t* dest, const wchar_t* src, size_t num)
return original_dest;
}
+size_t wcslcpy(wchar_t* dest, const wchar_t* src, size_t n)
+{
+ size_t i;
+ for (i = 0; i + 1 < n && src[i] != L'\0'; ++i)
+ dest[i] = src[i];
+ if (n)
+ dest[i] = L'\0';
+ for (; src[i] != L'\0'; ++i)
+ ; // Determine the length of src, don't copy.
+ return i;
+}
+
int wcscmp(const wchar_t* s1, const wchar_t* s2)
{
while (*s1 == *s2++)
diff --git a/Userland/Libraries/LibC/wchar.h b/Userland/Libraries/LibC/wchar.h
index b47b412cc3..12ef0f530c 100644
--- a/Userland/Libraries/LibC/wchar.h
+++ b/Userland/Libraries/LibC/wchar.h
@@ -29,6 +29,7 @@ struct tm;
size_t wcslen(const wchar_t*);
wchar_t* wcscpy(wchar_t*, const wchar_t*);
wchar_t* wcsncpy(wchar_t*, const wchar_t*, size_t);
+__attribute__((warn_unused_result)) size_t wcslcpy(wchar_t*, const wchar_t*, size_t);
int wcscmp(const wchar_t*, const wchar_t*);
int wcsncmp(const wchar_t*, const wchar_t*, size_t);
wchar_t* wcschr(const wchar_t*, int);