mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:28:11 +00:00
LibC, LibM: Add functions needed to compile python3
This commit is contained in:
parent
3042c942d8
commit
e7affa24dc
7 changed files with 136 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <AK/StdLibExtras.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <Kernel/Syscall.h>
|
||||
#include <alloca.h>
|
||||
#include <assert.h>
|
||||
|
@ -469,6 +470,28 @@ int wctomb(char*, wchar_t)
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
size_t wcstombs(char* dest, const wchar_t* src, size_t max)
|
||||
{
|
||||
char* originalDest = dest;
|
||||
while ((size_t)(dest - originalDest) < max) {
|
||||
StringView v { (const char*)src, sizeof(wchar_t) };
|
||||
|
||||
// FIXME: dependent on locale, for now utf-8 is supported.
|
||||
Utf8View utf8 { v };
|
||||
if (*utf8.begin() == '\0') {
|
||||
*dest = '\0';
|
||||
return (size_t)(dest - originalDest); // Exclude null character in returned size
|
||||
}
|
||||
|
||||
for (auto byte : utf8) {
|
||||
if (byte != '\0')
|
||||
*dest++ = byte;
|
||||
}
|
||||
++src;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
template<typename T, T min_value, T max_value>
|
||||
static T strtol_impl(const char* nptr, char** endptr, int base)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue