mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 18:57:36 +00:00
More LibC portability work while trying to get figlet building.
This commit is contained in:
parent
bb90c8ecab
commit
9160fd0d47
12 changed files with 128 additions and 2 deletions
4
LibC/alloca.h
Normal file
4
LibC/alloca.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
#define alloca __builtin_alloca
|
||||
|
33
LibC/ctype.h
33
LibC/ctype.h
|
@ -1,4 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#define isascii(c) (((c) & ~0x7f) == 0)
|
||||
inline int isascii(int ch)
|
||||
{
|
||||
return (ch & ~0x7f) == 0;
|
||||
}
|
||||
|
||||
inline int isspace(int ch)
|
||||
{
|
||||
return ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' == '\v';
|
||||
}
|
||||
|
||||
inline int islower(int c)
|
||||
{
|
||||
return c >= 'a' && c <= 'z';
|
||||
}
|
||||
|
||||
inline int isupper(int c)
|
||||
{
|
||||
return c >= 'A' && c <= 'Z';
|
||||
}
|
||||
|
||||
inline int tolower(int c)
|
||||
{
|
||||
if (isupper(c))
|
||||
return c | 0x20;
|
||||
return c;
|
||||
}
|
||||
|
||||
inline int toupper(int c)
|
||||
{
|
||||
if (islower(c))
|
||||
return c & ~0x20;
|
||||
return c;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,22 @@ static void sys_putch(char*&, char ch)
|
|||
putchar(ch);
|
||||
}
|
||||
|
||||
static FILE* __current_stream = nullptr;
|
||||
static void stream_putch(char*&, char ch)
|
||||
{
|
||||
write(__current_stream->fd, &ch, 1);
|
||||
}
|
||||
|
||||
int fprintf(FILE* fp, const char* fmt, ...)
|
||||
{
|
||||
__current_stream = fp;
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int ret = printfInternal(stream_putch, nullptr, fmt, ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int printf(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
|
@ -10,6 +10,7 @@ void free(void*);
|
|||
void* calloc(size_t nmemb, size_t);
|
||||
void* realloc(void *ptr, size_t);
|
||||
|
||||
|
||||
void exit(int status);
|
||||
void abort();
|
||||
|
||||
|
|
|
@ -40,6 +40,53 @@ void memcpy(void* dest, const void* src, size_t n)
|
|||
*(bdest++) = *(bsrc++);
|
||||
}
|
||||
|
||||
char* strcpy(char* dest, const char *src)
|
||||
{
|
||||
char* originalDest = dest;
|
||||
while ((*dest++ = *src++) != '\0');
|
||||
return originalDest;
|
||||
}
|
||||
|
||||
char* strncpy(char* dest, const char* src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < n && src[i] != '\0'; ++i)
|
||||
dest[i] = src[i];
|
||||
for ( ; i < n; ++i)
|
||||
dest[i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
char* strchr(const char* str, int c)
|
||||
{
|
||||
if (!str)
|
||||
return nullptr;
|
||||
char* ptr = (char*)str;
|
||||
while (*ptr != c)
|
||||
++ptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
char* strcat(char *dest, const char *src)
|
||||
{
|
||||
size_t destLength = strlen(dest);
|
||||
size_t i;
|
||||
for (i = 0 ; src[i] != '\0' ; i++)
|
||||
dest[destLength + i] = src[i];
|
||||
dest[destLength + i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
char* strncat(char *dest, const char *src, size_t n)
|
||||
{
|
||||
size_t destLength = strlen(dest);
|
||||
size_t i;
|
||||
for (i = 0 ; i < n && src[i] != '\0' ; i++)
|
||||
dest[destLength + i] = src[i];
|
||||
dest[destLength + i] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
const char* strerror(int errnum)
|
||||
{
|
||||
switch (errnum) {
|
||||
|
|
|
@ -9,6 +9,11 @@ size_t strlen(const char*);
|
|||
int strcmp(const char*, const char*);
|
||||
int memcmp(const void*, const void*, size_t);
|
||||
void memcpy(void*, const void*, size_t);
|
||||
char* strcpy(char* dest, const char* src);
|
||||
char* strncpy(char* dest, const char* src, size_t);
|
||||
char* strchr(const char*, int c);
|
||||
char* strcat(char *dest, const char *src);
|
||||
char* strncat(char *dest, const char *src, size_t);
|
||||
const char* strerror(int errnum);
|
||||
|
||||
__END_DECLS
|
||||
|
|
|
@ -64,12 +64,18 @@ pid_t waitpid(pid_t waitee, int* wstatus, int options)
|
|||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int lstat(const char* path, stat* statbuf)
|
||||
int lstat(const char* path, struct stat* statbuf)
|
||||
{
|
||||
int rc = Syscall::invoke(Syscall::PosixLstat, (dword)path, (dword)statbuf);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int stat(const char* path, struct stat* statbuf)
|
||||
{
|
||||
int rc = Syscall::invoke(Syscall::PosixStat, (dword)path, (dword)statbuf);
|
||||
__RETURN_WITH_ERRNO(rc, rc, -1);
|
||||
}
|
||||
|
||||
int chdir(const char* path)
|
||||
{
|
||||
int rc = Syscall::invoke(Syscall::PosixChdir, (dword)path);
|
||||
|
|
|
@ -16,6 +16,7 @@ pid_t waitpid(pid_t, int* wstatus, int options);
|
|||
int chdir(const char* path);
|
||||
char* getcwd(char* buffer, size_t size);
|
||||
int lstat(const char* path, struct stat* statbuf);
|
||||
int stat(const char* path, struct stat* statbuf);
|
||||
int sleep(unsigned seconds);
|
||||
int gethostname(char*, size_t);
|
||||
ssize_t readlink(const char* path, char* buffer, size_t);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue