LibC: Implement wcsdup

This commit is contained in:
Tim Schumacher 2021-11-07 17:49:01 +01:00 committed by Brian Gianforcaro
parent 7a44c11378
commit 8eca395e4c
Notes: sideshowbarker 2024-07-18 00:54:03 +09:00
2 changed files with 15 additions and 0 deletions
Userland/Libraries/LibC

View file

@ -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;

View file

@ -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*);