summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2021-11-07 17:49:01 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2021-12-19 18:22:41 -0800
commit8eca395e4c9ffd3ef8bd6e2bd18e445666e1b63b (patch)
treeb12f1064ff9f4d2c87422191521d8caf1ed75c71 /Userland
parent7a44c11378bf4920728f117a586dfa9c589992aa (diff)
downloadserenity-8eca395e4c9ffd3ef8bd6e2bd18e445666e1b63b.zip
LibC: Implement wcsdup
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibC/wchar.cpp14
-rw-r--r--Userland/Libraries/LibC/wchar.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/wchar.cpp b/Userland/Libraries/LibC/wchar.cpp
index 3188b54b5f..abe6d1609c 100644
--- a/Userland/Libraries/LibC/wchar.cpp
+++ b/Userland/Libraries/LibC/wchar.cpp
@@ -61,6 +61,20 @@ wchar_t* wcscpy(wchar_t* dest, const wchar_t* src)
return original_dest;
}
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsdup.html
+wchar_t* wcsdup(const wchar_t* str)
+{
+ size_t length = wcslen(str);
+ wchar_t* new_str = (wchar_t*)malloc(sizeof(wchar_t) * (length + 1));
+
+ if (!new_str) {
+ errno = ENOMEM;
+ return nullptr;
+ }
+
+ return wcscpy(new_str, str);
+}
+
wchar_t* wcsncpy(wchar_t* dest, const wchar_t* src, size_t num)
{
wchar_t* original_dest = dest;
diff --git a/Userland/Libraries/LibC/wchar.h b/Userland/Libraries/LibC/wchar.h
index e52869722d..98423e9b30 100644
--- a/Userland/Libraries/LibC/wchar.h
+++ b/Userland/Libraries/LibC/wchar.h
@@ -28,6 +28,7 @@ struct tm;
size_t wcslen(const wchar_t*);
wchar_t* wcscpy(wchar_t*, const wchar_t*);
+wchar_t* wcsdup(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*);