1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:27:42 +00:00

Enough compatibility work to make figlet build and run!

I ran out of steam writing library routines and imported two
BSD-licensed libc routines: sscanf() and getopt().

I will most likely rewrite them sooner or later. For now
I just wanted to see figlet running.
This commit is contained in:
Andreas Kling 2018-10-31 17:50:43 +01:00
parent 69c7a59e6f
commit 819ce91395
22 changed files with 714 additions and 36 deletions

View file

@ -4,6 +4,40 @@
extern "C" {
void* memset(void* dest, int c, size_t n)
{
byte* bdest = (byte*)dest;
for (; n; --n)
*(bdest++) = c;
return dest;
}
size_t strspn(const char* s, const char* accept)
{
const char* p = s;
cont:
char ch = *p++;
char ac;
for (const char* ap = accept; (ac = *ap++) != '\0';) {
if (ac == ch)
goto cont;
}
return p - 1 - s;
}
size_t strcspn(const char* s, const char* reject)
{
for (auto* p = s;;) {
char c = *p++;
auto* rp = reject;
char rc;
do {
if ((rc = *rp++) == c)
return p - 1 - s;
} while(rc);
}
}
size_t strlen(const char* str)
{
size_t len = 0;
@ -62,11 +96,22 @@ char* strchr(const char* str, int c)
if (!str)
return nullptr;
char* ptr = (char*)str;
while (*ptr != c)
while (*ptr && *ptr != c)
++ptr;
return ptr;
}
char* strrchr(const char* str, int ch)
{
char *last = nullptr;
char c;
for (; (c = *str); ++str) {
if (c == ch)
last = (char*)str;
}
return last;
}
char* strcat(char *dest, const char *src)
{
size_t destLength = strlen(dest);