mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +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
|
@ -1,3 +1,4 @@
|
|||
#include <AK/Assertions.h>
|
||||
#include <wchar.h>
|
||||
|
||||
extern "C" {
|
||||
|
@ -18,6 +19,14 @@ wchar_t* wcscpy(wchar_t* dest, const wchar_t* src)
|
|||
return originalDest;
|
||||
}
|
||||
|
||||
wchar_t* wcsncpy(wchar_t* dest, const wchar_t* src, size_t num)
|
||||
{
|
||||
wchar_t* originalDest = dest;
|
||||
while (((*dest++ = *src++) != '\0') && ((size_t)(dest - originalDest) < num))
|
||||
;
|
||||
return originalDest;
|
||||
}
|
||||
|
||||
int wcscmp(const wchar_t* s1, const wchar_t* s2)
|
||||
{
|
||||
while (*s1 == *s2++)
|
||||
|
@ -37,4 +46,79 @@ wchar_t* wcschr(const wchar_t* str, int c)
|
|||
}
|
||||
}
|
||||
|
||||
const wchar_t* wcsrchr(const wchar_t* str, wchar_t wc)
|
||||
{
|
||||
wchar_t* last = nullptr;
|
||||
wchar_t c;
|
||||
for (; (c = *str); ++str) {
|
||||
if (c == wc)
|
||||
last = const_cast<wchar_t*>(str);
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
wchar_t* wcscat(wchar_t* dest, const wchar_t* src)
|
||||
{
|
||||
size_t dest_length = wcslen(dest);
|
||||
size_t i;
|
||||
for (i = 0; src[i] != '\0'; i++)
|
||||
dest[dest_length + i] = src[i];
|
||||
dest[dest_length + i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
wchar_t* wcstok(wchar_t* str, const wchar_t* delim, wchar_t** ptr)
|
||||
{
|
||||
wchar_t* used_str = str;
|
||||
if (!used_str) {
|
||||
used_str = *ptr;
|
||||
}
|
||||
|
||||
size_t token_start = 0;
|
||||
size_t token_end = 0;
|
||||
size_t str_len = wcslen(used_str);
|
||||
size_t delim_len = wcslen(delim);
|
||||
|
||||
for (size_t i = 0; i < str_len; ++i) {
|
||||
bool is_proper_delim = false;
|
||||
|
||||
for (size_t j = 0; j < delim_len; ++j) {
|
||||
if (used_str[i] == delim[j]) {
|
||||
// Skip beginning delimiters
|
||||
if (token_end - token_start == 0) {
|
||||
++token_start;
|
||||
break;
|
||||
}
|
||||
|
||||
is_proper_delim = true;
|
||||
}
|
||||
}
|
||||
|
||||
++token_end;
|
||||
if (is_proper_delim && token_end > 0) {
|
||||
--token_end;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (used_str[token_start] == '\0')
|
||||
return nullptr;
|
||||
|
||||
if (token_end == 0) {
|
||||
return &used_str[token_start];
|
||||
}
|
||||
|
||||
used_str[token_end] = '\0';
|
||||
return &used_str[token_start];
|
||||
}
|
||||
|
||||
wchar_t* wcsncat(wchar_t* dest, const wchar_t* src, size_t n)
|
||||
{
|
||||
size_t dest_length = wcslen(dest);
|
||||
size_t i;
|
||||
for (i = 0; i < n && src[i] != '\0'; i++)
|
||||
dest[dest_length + i] = src[i];
|
||||
dest[dest_length + i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue